-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parse: unify function front matter parsing #69023
Conversation
This comment has been minimized.
This comment has been minimized.
Addressed the comments. :) |
This comment has been minimized.
This comment has been minimized.
r=me after rebase |
Same idea for `Unsafety` & use new span for better diagnostics.
use new span for better diagnostics.
@bors r=petrochenkov |
📌 Commit 9828559 has been approved by |
parse: unify function front matter parsing Part of #68728. - `const extern fn` feature gating is now done post-expansion such that we do not have conditional compatibilities of function qualifiers *in parsing*. - The `FnFrontMatter` grammar becomes: ```rust Extern = "extern" StringLit ; FnQual = "const"? "async"? "unsafe"? Extern? ; FnFrontMatter = FnQual "fn" ; ``` That is, all item contexts now *syntactically* allow `const async unsafe extern "C" fn` and use semantic restrictions to rule out combinations previously prevented syntactically. The semantic restrictions include in particular: - `fn`s in `extern { ... }` can have no qualifiers. - `const` and `async` cannot be combined. - We change `ast::{Unsafety, Spanned<Constness>}>` into `enum ast::{Unsafe, Const} { Yes(Span), No }` respectively. This change in formulation allow us to exclude `Span` in the case of `No`, which facilitates parsing. Moreover, we also add a `Span` to `IsAsync` which is renamed to `Async`. The new `Span`s in `Unsafety` and `Async` are then taken advantage of for better diagnostics. A reason this change was made is to have a more uniform and clear naming scheme. The HIR keeps the structures in AST (with those definitions moved into HIR) for now to avoid regressing perf. r? @petrochenkov
☀️ Test successful - checks-azure |
📣 Toolstate changed by #69023! Tested on commit be493fe. 💔 rustc-guide on linux: test-pass → test-fail (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra). |
Tested on commit rust-lang/rust@be493fe. Direct link to PR: <rust-lang/rust#69023> 💔 rustc-guide on linux: test-pass → test-fail (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).
(Toolstate failure is spurious, can be ignored.) |
Part of #68728.
const extern fn
feature gating is now done post-expansion such that we do not have conditional compatibilities of function qualifiers in parsing.The
FnFrontMatter
grammar becomes:That is, all item contexts now syntactically allow
const async unsafe extern "C" fn
and use semantic restrictions to rule out combinations previously prevented syntactically. The semantic restrictions include in particular:fn
s inextern { ... }
can have no qualifiers.const
andasync
cannot be combined.We change
ast::{Unsafety, Spanned<Constness>}>
intoenum ast::{Unsafe, Const} { Yes(Span), No }
respectively. This change in formulation allow us to excludeSpan
in the case ofNo
, which facilitates parsing. Moreover, we also add aSpan
toIsAsync
which is renamed toAsync
. The newSpan
s inUnsafety
andAsync
are then taken advantage of for better diagnostics. A reason this change was made is to have a more uniform and clear naming scheme.The HIR keeps the structures in AST (with those definitions moved into HIR) for now to avoid regressing perf.
r? @petrochenkov