From c643007a562004c0954bb6d4077caa19b1b6ed1c Mon Sep 17 00:00:00 2001 From: hdelc Date: Tue, 2 Aug 2022 10:05:11 -0400 Subject: [PATCH] Add exhaustive location checking for `doc_alias` attribute --- compiler/rustc_passes/src/check_attr.rs | 28 +++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 2fcd85b2a53..4ff706ddfc3 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -619,10 +619,30 @@ impl CheckAttrVisitor<'_> { } // we check the validity of params elsewhere Target::Param => return false, - Target::Expression => Some("expression"), - Target::Statement => Some("statement"), - Target::Arm => Some("match arm"), - _ => None, + Target::Expression | Target::Statement | Target::Arm => Some(target.name()), + Target::ExternCrate + | Target::Use + | Target::Static + | Target::Const + | Target::Fn + | Target::Closure + | Target::Mod + | Target::GlobalAsm + | Target::TyAlias + | Target::OpaqueTy + | Target::Enum + | Target::Variant + | Target::Struct + | Target::Field + | Target::Union + | Target::Trait + | Target::TraitAlias + | Target::Method(..) + | Target::ForeignFn + | Target::ForeignStatic + | Target::ForeignTy + | Target::GenericParam(..) + | Target::MacroDef => None, } { tcx.sess.emit_err(errors::DocAliasBadLocation { span, attr_str, location }); return false;