@@ -6743,7 +6743,15 @@ impl<'a> Parser<'a> {
6743
6743
} ;
6744
6744
6745
6745
// Parse both types and traits as a type, then reinterpret if necessary.
6746
- let ty_first = self . parse_ty ( ) ?;
6746
+ let err_path = |span| ast:: Path :: from_ident ( Ident :: new ( keywords:: Invalid . name ( ) , span) ) ;
6747
+ let ty_first = if self . token . is_keyword ( keywords:: For ) &&
6748
+ self . look_ahead ( 1 , |t| t != & token:: Lt ) {
6749
+ let span = self . prev_span . between ( self . span ) ;
6750
+ self . struct_span_err ( span, "missing trait in a trait impl" ) . emit ( ) ;
6751
+ P ( Ty { node : TyKind :: Path ( None , err_path ( span) ) , span, id : ast:: DUMMY_NODE_ID } )
6752
+ } else {
6753
+ self . parse_ty ( ) ?
6754
+ } ;
6747
6755
6748
6756
// If `for` is missing we try to recover.
6749
6757
let has_for = self . eat_keyword ( keywords:: For ) ;
@@ -6752,7 +6760,7 @@ impl<'a> Parser<'a> {
6752
6760
let ty_second = if self . token == token:: DotDot {
6753
6761
// We need to report this error after `cfg` expansion for compatibility reasons
6754
6762
self . bump ( ) ; // `..`, do not add it to expected tokens
6755
- Some ( P ( Ty { node : TyKind :: Err , span : self . prev_span , id : ast :: DUMMY_NODE_ID } ) )
6763
+ Some ( DummyResult :: raw_ty ( self . prev_span , true ) )
6756
6764
} else if has_for || self . token . can_begin_type ( ) {
6757
6765
Some ( self . parse_ty ( ) ?)
6758
6766
} else {
@@ -6782,7 +6790,7 @@ impl<'a> Parser<'a> {
6782
6790
TyKind :: Path ( None , path) => path,
6783
6791
_ => {
6784
6792
self . span_err ( ty_first. span , "expected a trait, found type" ) ;
6785
- ast :: Path :: from_ident ( Ident :: new ( keywords :: Invalid . name ( ) , ty_first. span ) )
6793
+ err_path ( ty_first. span )
6786
6794
}
6787
6795
} ;
6788
6796
let trait_ref = TraitRef { path, ref_id : ty_first. id } ;
0 commit comments