Skip to content

Commit

Permalink
Visit attributes of trait impl items during AST validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Nov 8, 2022
1 parent 6b23a7e commit 5ef85bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {

walk_list!(this, visit_assoc_item, items, AssocCtxt::Impl);
});
walk_list!(self, visit_attribute, &item.attrs);
return; // Avoid visiting again.
}
ItemKind::Impl(box Impl {
Expand Down Expand Up @@ -1168,7 +1169,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
});
walk_list!(self, visit_assoc_item, items, AssocCtxt::Trait);
walk_list!(self, visit_attribute, &item.attrs);
return;
return; // Avoid visiting again
}
ItemKind::Mod(unsafety, ref mod_kind) => {
if let Unsafe::Yes(span) = unsafety {
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/on-unimplemented/issue-104140.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(rustc_attrs)]

trait Foo {}

#[rustc_on_unimplemented] //~ ERROR malformed `rustc_on_unimplemented` attribute input
impl Foo for u32 {}

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/on-unimplemented/issue-104140.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: malformed `rustc_on_unimplemented` attribute input
--> $DIR/issue-104140.rs:5:1
|
LL | #[rustc_on_unimplemented]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[rustc_on_unimplemented = "message"]
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: aborting due to previous error

0 comments on commit 5ef85bb

Please sign in to comment.