Consider deferring parse error on sensibly placed unsafe keyword #68048
Labels
A-parser
Area: The lexing & parsing of Rust source code to an AST
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-lang
Relevant to the language team
Uh oh!
There was an error while loading. Please reload this page.
In DSLs based on an attribute proc macro, it comes up that we want to require a syntactic safety claim on some item which would not normally allow an
unsafe
keyword in Rust syntax.Currently these fail early with a parse error; you can reproduce by replacing
my_macro
withcfg(any())
.I would like to suggest allowing these to parse and deferring the error until after macro expansion, giving attribute macros a chance to strip
unsafe
from a mod or foreign mod and assign their own semantics for what it means. Ifunsafe
remains on a mod or foreign mod after macro expansion we can keep that an error; I am not proposing attaching any new semantics to that.We already do similar deferral of errors on "sensibly placed" keywords such as
async
on a trait method orpub
inside an enum or on an impl:Mentioning @Centril who requested an issue to discuss this further.
The text was updated successfully, but these errors were encountered: