Fix target checking for some attributes on macro calls#156569
Fix target checking for some attributes on macro calls#156569JonathanBrouwer wants to merge 2 commits into
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing |
|
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
c960552 to
5f14882
Compare
|
r? @mejrs |
| /// This is a list of default targets to which a attribute can be applied | ||
| /// This is used for attributes that are not parted to the new target checking system yet can use this list as a placeholder. | ||
| /// This excludes `Target::MacroCall`, as attributes on macro calls are otherwise not checked for parsed attributes. | ||
| pub(crate) const DEFAULT_TARGETS: &'static [Policy] = { |
There was a problem hiding this comment.
This being a separate list is quite ugly, I'm planning on fixing this in the future by having some way to pass a pattern to the target checking, for example by having AllowedTargets::AllowFn(|target| match target { ... })
There was a problem hiding this comment.
Note that ALL_TARGETS is still used by the diagnostic attrs & rustc_dummy
5f14882 to
d98e484
Compare
d98e484 to
d69f6ba
Compare
| } | ||
|
|
||
| /// This is a list of default targets to which a attribute can be applied | ||
| /// This is used for attributes that are not parted to the new target checking system yet can use this list as a placeholder. |
There was a problem hiding this comment.
| /// This is used for attributes that are not parted to the new target checking system yet can use this list as a placeholder. | |
| /// This is used for attributes that are not ported to the new target checking system yet and can use this list as a placeholder. |
two nits:
parted=>ported- it might be two sentences?
There was a problem hiding this comment.
These attributes don't have target checks during parsing because they need access to hir, not because we haven't gotten around to moving them around.
Unless that's something you're actively planning to change, we shouldn't say "yet".
There was a problem hiding this comment.
I know I suggested it but now I'm not sure CHECKED_LATER is a good idea. I think we should just move as many checks as we can to attribute parsing instead.
Take for example may_dangle: currently it checks in check_attr that it's on a generic param, and then that it's on a lifetime/type generic in a Drop impl.
Instead we should just move that first check into attr parsing and leave the drop impl check in check_attr.
Similar for the other attributes. Thoughts?
| /// This is used for attributes that are not parted to the new target checking system yet can use this list as a placeholder. | ||
| /// This excludes `Target::MacroCall`, as attributes on macro calls are otherwise not checked for parsed attributes. | ||
| pub(crate) const CHECKED_LATER: &'static [Policy] = { | ||
| use Policy::Allow; |
There was a problem hiding this comment.
| use Policy::Allow; |
Redundant import.
|
|
||
| /// This is a list of default targets to which a attribute can be applied | ||
| /// This is used for attributes that are not parted to the new target checking system yet can use this list as a placeholder. | ||
| /// This excludes `Target::MacroCall`, as attributes on macro calls are otherwise not checked for parsed attributes. |
There was a problem hiding this comment.
| /// This excludes `Target::MacroCall`, as attributes on macro calls are otherwise not checked for parsed attributes. | |
| /// This excludes `Target::MacroCall`, as attributes on macro calls are otherwise not checked for parsed attributes because `check_attr.rs` runs after macro expansion. |
or something similar
| //~| WARN previously accepted | ||
| test!(); | ||
|
|
||
| fn main() {} |
There was a problem hiding this comment.
Please merge this file into https://github.com/rust-lang/rust/blob/main/tests/ui/attributes/attr-on-mac-call.rs instead.
| #![feature(sanitize)] | ||
| #![feature(register_tool)] | ||
| #![feature(export_stable)] | ||
| #![feature(lang_items)] | ||
| #![feature(dropck_eyepatch)] |
There was a problem hiding this comment.
I propose we just error for all these unstable attributes on macro call positions, no need to bother with a lint or fcw.
| added_fake_targets.push(target_group_name); | ||
| } | ||
|
|
||
| /// This is a list of default targets to which a attribute can be applied |
There was a problem hiding this comment.
| /// This is a list of default targets to which a attribute can be applied | |
| /// This is a list of default targets to which a attribute can be applied | |
| /// |
Let's not have this big paragraph included in the module level docs :)
| } | ||
|
|
||
| /// This is a list of default targets to which a attribute can be applied | ||
| /// This is used for attributes that are not parted to the new target checking system yet can use this list as a placeholder. |
There was a problem hiding this comment.
These attributes don't have target checks during parsing because they need access to hir, not because we haven't gotten around to moving them around.
Unless that's something you're actively planning to change, we shouldn't say "yet".
| | ^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
| = help: `#[link]` can be applied to associated consts, associated types, const parameters, const parameters, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, function params, functions, global asms, impl blocks, lifetime parameters, lifetime parameters, macro defs, match arms, modules, pattern fields, statics, struct fields, struct fields, trait aliases, traits, type aliases, type parameters, type parameters, use statements, and where predicates |
There was a problem hiding this comment.
We shouldn't be saying this huge list of "valid" targets.
|
Reminder, once the PR becomes ready for a review, use |
Fixes #156499