File tree 3 files changed +24
-1
lines changed
3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -6716,8 +6716,16 @@ impl<'a> Parser<'a> {
6716
6716
ast:: ImplPolarity :: Positive
6717
6717
} ;
6718
6718
6719
+ let possible_missing_trait = self . look_ahead ( 0 , |t| t. is_keyword ( keywords:: For ) ) ;
6720
+
6719
6721
// Parse both types and traits as a type, then reinterpret if necessary.
6720
- let ty_first = self . parse_ty ( ) ?;
6722
+ let ty_first = self . parse_ty ( ) . map_err ( |mut err| {
6723
+ if possible_missing_trait {
6724
+ err. help ( "did you forget a trait name after `impl`?" ) ;
6725
+ }
6726
+
6727
+ err
6728
+ } ) ?;
6721
6729
6722
6730
// If `for` is missing we try to recover.
6723
6731
let has_for = self . eat_keyword ( keywords:: For ) ;
Original file line number Diff line number Diff line change
1
+ struct T ;
2
+
3
+ impl for T { }
4
+
5
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: expected `<`, found `T`
2
+ --> $DIR/issue-56031.rs:3:10
3
+ |
4
+ LL | impl for T {}
5
+ | ^ expected `<` here
6
+ |
7
+ = help: did you forget a trait name after `impl`?
8
+
9
+ error: aborting due to previous error
10
+
You can’t perform that action at this time.
0 commit comments