Rollup merge of #80920 - rylev:check_attr-refactor, r=davidtwco
Visit more targets when validating attributes This begins to address #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`
This commit is contained in:
commit
ac1d26bcd3
6 changed files with 50 additions and 17 deletions
|
@ -1101,17 +1101,6 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
intravisit::walk_arm(self, arm);
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
|
||||
self.check_attributes(
|
||||
macro_def.hir_id,
|
||||
¯o_def.attrs,
|
||||
¯o_def.span,
|
||||
Target::MacroDef,
|
||||
None,
|
||||
);
|
||||
intravisit::walk_macro_def(self, macro_def);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, f_item: &'tcx ForeignItem<'tcx>) {
|
||||
let target = Target::from_foreign_item(f_item);
|
||||
self.check_attributes(
|
||||
|
@ -1157,6 +1146,23 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
self.check_attributes(variant.id, variant.attrs, &variant.span, Target::Variant, None);
|
||||
intravisit::walk_variant(self, variant, generics, item_id)
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
|
||||
self.check_attributes(
|
||||
macro_def.hir_id,
|
||||
macro_def.attrs,
|
||||
¯o_def.span,
|
||||
Target::MacroDef,
|
||||
None,
|
||||
);
|
||||
intravisit::walk_macro_def(self, macro_def);
|
||||
}
|
||||
|
||||
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
|
||||
self.check_attributes(param.hir_id, param.attrs, ¶m.span, Target::Param, None);
|
||||
|
||||
intravisit::walk_param(self, param);
|
||||
}
|
||||
}
|
||||
|
||||
fn is_c_like_enum(item: &Item<'_>) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue