Prevent ICE for doc_alias on match arm, statement, expression

This commit is contained in:
hdelc 2022-07-30 17:45:09 -04:00
parent dcb444af0a
commit e98b0e8ee7
3 changed files with 29 additions and 2 deletions

View file

@ -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 });

View file

@ -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
}
}
}

View file

@ -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