Skip to content

Commit e98b0e8

Browse files
committed
Prevent ICE for doc_alias on match arm, statement, expression
1 parent dcb444a commit e98b0e8

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,9 @@ impl CheckAttrVisitor<'_> {
619619
}
620620
// we check the validity of params elsewhere
621621
Target::Param => return false,
622+
Target::Expression => Some("expression"),
623+
Target::Statement => Some("statement"),
624+
Target::Arm => Some("match arm"),
622625
_ => None,
623626
} {
624627
tcx.sess.emit_err(errors::DocAliasBadLocation { span, attr_str, location });

src/test/ui/rustdoc/check-doc-alias-attr-location.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ impl Foo for Bar {
2121
type X = i32;
2222
fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X {
2323
//~^ ERROR
24-
0
24+
#[doc(alias = "stmt")] //~ ERROR
25+
let x = 0;
26+
#[doc(alias = "expr")] //~ ERROR
27+
match x {
28+
#[doc(alias = "arm")] //~ ERROR
29+
_ => 0
30+
}
2531
}
2632
}

src/test/ui/rustdoc/check-doc-alias-attr-location.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,23 @@ error: `#[doc(alias = "...")]` isn't allowed on type alias in implementation blo
2828
LL | #[doc(alias = "assoc")]
2929
| ^^^^^^^^^^^^^^^
3030

31-
error: aborting due to 5 previous errors
31+
error: `#[doc(alias = "...")]` isn't allowed on statement
32+
--> $DIR/check-doc-alias-attr-location.rs:24:15
33+
|
34+
LL | #[doc(alias = "stmt")]
35+
| ^^^^^^^^^^^^^^
36+
37+
error: `#[doc(alias = "...")]` isn't allowed on expression
38+
--> $DIR/check-doc-alias-attr-location.rs:26:15
39+
|
40+
LL | #[doc(alias = "expr")]
41+
| ^^^^^^^^^^^^^^
42+
43+
error: `#[doc(alias = "...")]` isn't allowed on match arm
44+
--> $DIR/check-doc-alias-attr-location.rs:28:19
45+
|
46+
LL | #[doc(alias = "arm")]
47+
| ^^^^^^^^^^^^^
48+
49+
error: aborting due to 8 previous errors
3250

0 commit comments

Comments
 (0)