You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A quick search (for attrs:) in the HIR definition finds these additional types that can contain attributes (they're also missing from the hir::Targetenum, which should probably be renamed to AttrTarget but that's besides the point):
forbid, and warn are the only allowed built-in attributes in function parameters",
But it's not as uniform and future-proof as it could be. It might even be worth having a contextual attribute Target, and handling all attributes on visit_attr, or a hybrid solution that ICEs when visit_attr comes across an attribute not already handled.
And I did end up finding at least one bug, this compiles without any warnings (try on playground):
Visit more targets when validating attributes
This begins to address rust-lang#80048, allowing for additional validation of attributes.
There are more refactorings that can be done, though I think they should be tackled in additional PRs:
* ICE when a builtin attribute is encountered that is not checked
* Move some of the attr checking done `ast_validation` into `rustc_passes`
* note that this requires a bit of additional refactoring, especially of extern items which currently parse attributes (and thus are a part of the AST) but do not possess attributes in their HIR representation.
* Rename `Target` to `AttributeTarget`
* Refactor attribute validation completely to go through `Visitor::visit_attribute`.
* This would require at a minimum passing `Target` into this method which might be too big of a refactoring to be worth it.
* It's also likely not possible to do all the validation this way as some validation requires knowing what other attributes a target has.
r? `@davidtwco`
The
check_attr
visitor here is missing several methods:rust/compiler/rustc_passes/src/check_attr.rs
Lines 866 to 936 in e261649
A quick search (for
attrs:
) in the HIR definition finds these additional types that can contain attributes (they're also missing from thehir::Target
enum
, which should probably be renamed toAttrTarget
but that's besides the point):(click to see definition code snippets)
(summary:
GenericParam
,MacroDef
,Arm
,Param
,StructField
)GenericParam
rust/compiler/rustc_hir/src/hir.rs
Lines 425 to 428 in e261649
MacroDef
(is this handled elsewhere?)rust/compiler/rustc_hir/src/hir.rs
Lines 722 to 725 in e261649
Arm
rust/compiler/rustc_hir/src/hir.rs
Lines 1147 to 1151 in e261649
Param
rust/compiler/rustc_hir/src/hir.rs
Lines 2183 to 2184 in e261649
StructField
rust/compiler/rustc_hir/src/hir.rs
Lines 2390 to 2397 in e261649
This isn't necessary a bug for some of them, as there is special validation elsewhere, e.g.:
rust/compiler/rustc_ast_passes/src/ast_validation.rs
Lines 377 to 378 in e261649
But it's not as uniform and future-proof as it could be. It might even be worth having a contextual attribute
Target
, and handling all attributes onvisit_attr
, or a hybrid solution that ICEs whenvisit_attr
comes across an attribute not already handled.And I did end up finding at least one bug, this compiles without any warnings (try on playground):
cc @varkor @davidtwco @petrochenkov
The text was updated successfully, but these errors were encountered: