Add allowed list check on EII implementations attributes#159173
Add allowed list check on EII implementations attributes#159173chenyukang wants to merge 1 commit into
Conversation
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
23be887 to
9c36383
Compare
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| if let Some(no_mangle_span) = | ||
| find_attr!(attrs, NoMangle(no_mangle_span) => *no_mangle_span) |
There was a problem hiding this comment.
This should also reject #[export_name] and probably #[link_section].
9c36383 to
81a1b49
Compare
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_hir/src/attrs |
81a1b49 to
c7cb405
Compare
This comment has been minimized.
This comment has been minimized.
|
Maybe we ought to have an allowlist of attributes rather than error on these particular attributes? I'm also a bit worried about someone later down the line adding some new (possibly link related) attribute and not including it in this check. |
c7cb405 to
8e3fe6d
Compare
maybe allowlist contains |
|
Seems like a reasonable list. |
I tried to get a more overwhole status on eii, this #125418 is the best place to track. |
|
I don't know if the current EII syntax is expected to be stabilized eventually or if the intent is for the syntax from the RFC to be implemented eventually with |
|
For reference, attributes on eii declarations are handled via allowlist: rust/compiler/rustc_builtin_macros/src/eii.rs Lines 180 to 228 in da80ed0 I would expect attributes on implementations to be handled similarly.
It's an experiment so we can diverge from the original proposal. Once we are happy with the implementation the rfc should be updated accordingly. |
35bc796 to
30cc6b4
Compare
| } | ||
|
|
||
| // Check EII implementation attributes with a allowed list | ||
| fn check_eii_impl_attrs(&self, attrs: &[Attribute], eii_impls: &[EiiImpl]) { |
There was a problem hiding this comment.
I moved the checking to here in ast_validation, since macro expansion finished,
and leaves the final attributes, similar with
https://github.com/chenyukang/rust/blob/30cc6b46e8bb20318b05443cb80f1e50119ba971/compiler/rustc_ast_passes/src/ast_validation.rs#L522-L532
the old place where depends on HIR, HIR converts some attributes into variants without a uniform path or span.
This comment has been minimized.
This comment has been minimized.
30cc6b4 to
265407a
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
☔ The latest upstream changes (presumably #159293) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
|
I think someone more familiar with attribute parsing/validation should review this. I don't know the advantages and disadvantages of the various locations attributes are validated. |
|
Can you update a test to include
I think it's ~fine to do it like this. We could have the eii impl macro leave behind a trace attribute so we can still do this check post-expansion and keep it in check_attr.rs. Not sure what the best course of action is. If a trace attribute is useful elsewhere, then maybe we should do that. |
|
|
|
(might take me a few days to get around to it, but happy to take a look) |
Fixes #158293
Fixes #159015
r? @bjorn3