Skip to content

Commit

Permalink
Adds diagnostic message and UI test.
Browse files Browse the repository at this point in the history
  • Loading branch information
repnop authored and petrochenkov committed Mar 7, 2019
1 parent 88f755f commit 00887f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -6716,8 +6716,16 @@ impl<'a> Parser<'a> {
ast::ImplPolarity::Positive
};

let possible_missing_trait = self.look_ahead(0, |t| t.is_keyword(keywords::For));

// Parse both types and traits as a type, then reinterpret if necessary.
let ty_first = self.parse_ty()?;
let ty_first = self.parse_ty().map_err(|mut err| {
if possible_missing_trait {
err.help("did you forget a trait name after `impl`?");
}

err
})?;

// If `for` is missing we try to recover.
let has_for = self.eat_keyword(keywords::For);
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/issues/issue-56031.rs
@@ -0,0 +1,5 @@
struct T;

impl for T {}

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/issues/issue-56031.stderr
@@ -0,0 +1,10 @@
error: expected `<`, found `T`
--> $DIR/issue-56031.rs:3:10
|
LL | impl for T {}
| ^ expected `<` here
|
= help: did you forget a trait name after `impl`?

error: aborting due to previous error

0 comments on commit 00887f3

Please sign in to comment.