Skip to content

Commit 47f9d89

Browse files
authored
Rollup merge of #104148 - fmease:fix-104140, r=petrochenkov
Visit attributes of trait impl items during AST validation Fixes #104140. This fix might not be backward compatible (in practice) since we now validate more attributes than before. Should I write more tests? `@rustbot` label A-attributes
2 parents e309b79 + 5ef85bb commit 47f9d89

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10511051

10521052
walk_list!(this, visit_assoc_item, items, AssocCtxt::Impl);
10531053
});
1054+
walk_list!(self, visit_attribute, &item.attrs);
10541055
return; // Avoid visiting again.
10551056
}
10561057
ItemKind::Impl(box Impl {
@@ -1168,7 +1169,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11681169
});
11691170
walk_list!(self, visit_assoc_item, items, AssocCtxt::Trait);
11701171
walk_list!(self, visit_attribute, &item.attrs);
1171-
return;
1172+
return; // Avoid visiting again
11721173
}
11731174
ItemKind::Mod(unsafety, ref mod_kind) => {
11741175
if let Unsafe::Yes(span) = unsafety {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(rustc_attrs)]
2+
3+
trait Foo {}
4+
5+
#[rustc_on_unimplemented] //~ ERROR malformed `rustc_on_unimplemented` attribute input
6+
impl Foo for u32 {}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: malformed `rustc_on_unimplemented` attribute input
2+
--> $DIR/issue-104140.rs:5:1
3+
|
4+
LL | #[rustc_on_unimplemented]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
help: the following are the possible correct uses
8+
|
9+
LL | #[rustc_on_unimplemented = "message"]
10+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11+
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
12+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
14+
error: aborting due to previous error
15+

0 commit comments

Comments
 (0)