Treat macros as HIR items
This commit is contained in:
parent
ac50a53359
commit
8c62fa0575
31 changed files with 162 additions and 256 deletions
|
@ -1723,6 +1723,16 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
|
||||
// Historically we've run more checks on non-exported than exported macros,
|
||||
// so this lets us continue to run them while maintaining backwards compatibility.
|
||||
// In the long run, the checks should be harmonized.
|
||||
if let ItemKind::Macro(ref macro_def) = item.kind {
|
||||
let def_id = item.def_id.to_def_id();
|
||||
if macro_def.macro_rules && !self.tcx.has_attr(def_id, sym::macro_export) {
|
||||
check_non_exported_macro_for_invalid_attrs(self.tcx, item);
|
||||
}
|
||||
}
|
||||
|
||||
let target = Target::from_item(item);
|
||||
self.check_attributes(item.hir_id(), &item.span, target, Some(ItemLike::Item(item)));
|
||||
intravisit::walk_item(self, item)
|
||||
|
@ -1795,11 +1805,6 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
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(), ¯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, ¶m.span, Target::Param, None);
|
||||
|
||||
|
@ -1848,7 +1853,9 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_invalid_macro_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
|
||||
fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>) {
|
||||
let attrs = tcx.hir().attrs(item.hir_id());
|
||||
|
||||
for attr in attrs {
|
||||
if attr.has_name(sym::inline) {
|
||||
struct_span_err!(
|
||||
|
@ -1869,8 +1876,6 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
|
|||
if module_def_id.is_top_level_module() {
|
||||
check_attr_visitor.check_attributes(CRATE_HIR_ID, &DUMMY_SP, Target::Mod, None);
|
||||
check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs());
|
||||
tcx.hir().visit_exported_macros_in_krate(check_attr_visitor);
|
||||
check_invalid_macro_level_attr(tcx, tcx.hir().krate().non_exported_macro_attrs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue