@@ -6716,16 +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
-
6721
6719
// Parse both types and traits as a type, then reinterpret if necessary.
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
- } ) ?;
6720
+ let err_path = |span| ast:: Path :: from_ident ( Ident :: new ( keywords:: Invalid . name ( ) , span) ) ;
6721
+ let ty_first = if self . token . is_keyword ( keywords:: For ) &&
6722
+ self . look_ahead ( 1 , |t| t != & token:: Lt ) {
6723
+ let span = self . prev_span . between ( self . span ) ;
6724
+ self . struct_span_err ( span, "missing trait in a trait impl" ) . emit ( ) ;
6725
+ P ( Ty { node : TyKind :: Path ( None , err_path ( span) ) , span, id : ast:: DUMMY_NODE_ID } )
6726
+ } else {
6727
+ self . parse_ty ( ) ?
6728
+ } ;
6729
6729
6730
6730
// If `for` is missing we try to recover.
6731
6731
let has_for = self . eat_keyword ( keywords:: For ) ;
@@ -6734,7 +6734,7 @@ impl<'a> Parser<'a> {
6734
6734
let ty_second = if self . token == token:: DotDot {
6735
6735
// We need to report this error after `cfg` expansion for compatibility reasons
6736
6736
self . bump ( ) ; // `..`, do not add it to expected tokens
6737
- Some ( P ( Ty { node : TyKind :: Err , span : self . prev_span , id : ast :: DUMMY_NODE_ID } ) )
6737
+ Some ( DummyResult :: raw_ty ( self . prev_span , true ) )
6738
6738
} else if has_for || self . token . can_begin_type ( ) {
6739
6739
Some ( self . parse_ty ( ) ?)
6740
6740
} else {
@@ -6764,7 +6764,7 @@ impl<'a> Parser<'a> {
6764
6764
TyKind :: Path ( None , path) => path,
6765
6765
_ => {
6766
6766
self . span_err ( ty_first. span , "expected a trait, found type" ) ;
6767
- ast :: Path :: from_ident ( Ident :: new ( keywords :: Invalid . name ( ) , ty_first. span ) )
6767
+ err_path ( ty_first. span )
6768
6768
}
6769
6769
} ;
6770
6770
let trait_ref = TraitRef { path, ref_id : ty_first. id } ;
0 commit comments