diff options
Diffstat (limited to 'compiler/rustc_passes/src/check_attr.rs')
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 87d46e3e506..7880e629e91 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -183,6 +183,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Attribute::Parsed(AttributeKind::Naked(attr_span)) => { self.check_naked(hir_id, *attr_span, span, target) } + Attribute::Parsed(AttributeKind::NoImplicitPrelude(attr_span)) => self + .check_generic_attr( + hir_id, + sym::no_implicit_prelude, + *attr_span, + target, + Target::Mod, + ), Attribute::Parsed(AttributeKind::TrackCaller(attr_span)) => { self.check_track_caller(hir_id, *attr_span, attrs, span, target) } @@ -289,16 +297,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> { [sym::macro_use, ..] | [sym::macro_escape, ..] => { self.check_macro_use(hir_id, attr, target) } - [sym::path, ..] => self.check_generic_attr(hir_id, attr, target, Target::Mod), + [sym::path, ..] => self.check_generic_attr_unparsed(hir_id, attr, target, Target::Mod), [sym::macro_export, ..] => self.check_macro_export(hir_id, attr, target), [sym::ignore, ..] | [sym::should_panic, ..] => { - self.check_generic_attr(hir_id, attr, target, Target::Fn) + self.check_generic_attr_unparsed(hir_id, attr, target, Target::Fn) } [sym::automatically_derived, ..] => { - self.check_generic_attr(hir_id, attr, target, Target::Impl) - } - [sym::no_implicit_prelude, ..] => { - self.check_generic_attr(hir_id, attr, target, Target::Mod) + self.check_generic_attr_unparsed(hir_id, attr, target, Target::Impl) } [sym::proc_macro, ..] => { self.check_proc_macro(hir_id, target, ProcMacroKind::FunctionLike) @@ -307,7 +312,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.check_proc_macro(hir_id, target, ProcMacroKind::Attribute); } [sym::proc_macro_derive, ..] => { - self.check_generic_attr(hir_id, attr, target, Target::Fn); + self.check_generic_attr_unparsed(hir_id, attr, target, Target::Fn); self.check_proc_macro(hir_id, target, ProcMacroKind::Derive) } [sym::autodiff_forward, ..] | [sym::autodiff_reverse, ..] => { @@ -616,7 +621,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - fn check_generic_attr( + /// FIXME: Remove when all attributes are ported to the new parser + fn check_generic_attr_unparsed( &self, hir_id: HirId, attr: &Attribute, @@ -639,6 +645,27 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } + fn check_generic_attr( + &self, + hir_id: HirId, + attr_name: Symbol, + attr_span: Span, + target: Target, + allowed_target: Target, + ) { + if target != allowed_target { + self.tcx.emit_node_span_lint( + UNUSED_ATTRIBUTES, + hir_id, + attr_span, + errors::OnlyHasEffectOn { + attr_name: attr_name.to_string(), + target_name: allowed_target.name().replace(' ', "_"), + }, + ); + } + } + /// Checks if `#[naked]` is applied to a function definition. fn check_naked(&self, hir_id: HirId, attr_span: Span, span: Span, target: Target) { match target { |
