Adds diagnostic message and UI test.
This commit is contained in:
committed by
Vadim Petrochenkov
parent
88f755f8a8
commit
00887f39d1
@@ -6716,8 +6716,16 @@ impl<'a> Parser<'a> {
|
|||||||
ast::ImplPolarity::Positive
|
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.
|
// 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.
|
// If `for` is missing we try to recover.
|
||||||
let has_for = self.eat_keyword(keywords::For);
|
let has_for = self.eat_keyword(keywords::For);
|
||||||
|
|||||||
5
src/test/ui/issues/issue-56031.rs
Normal file
5
src/test/ui/issues/issue-56031.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
struct T;
|
||||||
|
|
||||||
|
impl for T {}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
10
src/test/ui/issues/issue-56031.stderr
Normal file
10
src/test/ui/issues/issue-56031.stderr
Normal file
@@ -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
|
||||||
|
|
||||||
Reference in New Issue
Block a user