@@ -6732,7 +6732,15 @@ impl<'a> Parser<'a> {
6732
6732
} ;
6733
6733
6734
6734
// Parse both types and traits as a type, then reinterpret if necessary.
6735
- let ty_first = self . parse_ty ( ) ?;
6735
+ let err_path = |span| ast:: Path :: from_ident ( Ident :: new ( keywords:: Invalid . name ( ) , span) ) ;
6736
+ let ty_first = if self . token . is_keyword ( keywords:: For ) &&
6737
+ self . look_ahead ( 1 , |t| t != & token:: Lt ) {
6738
+ let span = self . prev_span . between ( self . span ) ;
6739
+ self . struct_span_err ( span, "missing trait in a trait impl" ) . emit ( ) ;
6740
+ P ( Ty { node : TyKind :: Path ( None , err_path ( span) ) , span, id : ast:: DUMMY_NODE_ID } )
6741
+ } else {
6742
+ self . parse_ty ( ) ?
6743
+ } ;
6736
6744
6737
6745
// If `for` is missing we try to recover.
6738
6746
let has_for = self . eat_keyword ( keywords:: For ) ;
@@ -6741,7 +6749,7 @@ impl<'a> Parser<'a> {
6741
6749
let ty_second = if self . token == token:: DotDot {
6742
6750
// We need to report this error after `cfg` expansion for compatibility reasons
6743
6751
self . bump ( ) ; // `..`, do not add it to expected tokens
6744
- Some ( P ( Ty { node : TyKind :: Err , span : self . prev_span , id : ast :: DUMMY_NODE_ID } ) )
6752
+ Some ( DummyResult :: raw_ty ( self . prev_span , true ) )
6745
6753
} else if has_for || self . token . can_begin_type ( ) {
6746
6754
Some ( self . parse_ty ( ) ?)
6747
6755
} else {
@@ -6771,7 +6779,7 @@ impl<'a> Parser<'a> {
6771
6779
TyKind :: Path ( None , path) => path,
6772
6780
_ => {
6773
6781
self . span_err ( ty_first. span , "expected a trait, found type" ) ;
6774
- ast :: Path :: from_ident ( Ident :: new ( keywords :: Invalid . name ( ) , ty_first. span ) )
6782
+ err_path ( ty_first. span )
6775
6783
}
6776
6784
} ;
6777
6785
let trait_ref = TraitRef { path, ref_id : ty_first. id } ;
0 commit comments