diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index fde12b9eee6..2fcd85b2a53 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -619,6 +619,9 @@ 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, } { tcx.sess.emit_err(errors::DocAliasBadLocation { span, attr_str, location }); diff --git a/src/test/ui/rustdoc/check-doc-alias-attr-location.rs b/src/test/ui/rustdoc/check-doc-alias-attr-location.rs index 4738e5116b4..10609e5d8f4 100644 --- a/src/test/ui/rustdoc/check-doc-alias-attr-location.rs +++ b/src/test/ui/rustdoc/check-doc-alias-attr-location.rs @@ -21,6 +21,12 @@ impl Foo for Bar { type X = i32; fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X { //~^ ERROR - 0 + #[doc(alias = "stmt")] //~ ERROR + let x = 0; + #[doc(alias = "expr")] //~ ERROR + match x { + #[doc(alias = "arm")] //~ ERROR + _ => 0 + } } } diff --git a/src/test/ui/rustdoc/check-doc-alias-attr-location.stderr b/src/test/ui/rustdoc/check-doc-alias-attr-location.stderr index 650a82a23a9..19b2dd1e084 100644 --- a/src/test/ui/rustdoc/check-doc-alias-attr-location.stderr +++ b/src/test/ui/rustdoc/check-doc-alias-attr-location.stderr @@ -28,5 +28,23 @@ error: `#[doc(alias = "...")]` isn't allowed on type alias in implementation blo LL | #[doc(alias = "assoc")] | ^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: `#[doc(alias = "...")]` isn't allowed on statement + --> $DIR/check-doc-alias-attr-location.rs:24:15 + | +LL | #[doc(alias = "stmt")] + | ^^^^^^^^^^^^^^ + +error: `#[doc(alias = "...")]` isn't allowed on expression + --> $DIR/check-doc-alias-attr-location.rs:26:15 + | +LL | #[doc(alias = "expr")] + | ^^^^^^^^^^^^^^ + +error: `#[doc(alias = "...")]` isn't allowed on match arm + --> $DIR/check-doc-alias-attr-location.rs:28:19 + | +LL | #[doc(alias = "arm")] + | ^^^^^^^^^^^^^ + +error: aborting due to 8 previous errors