@@ -495,20 +495,28 @@ impl<'a> Parser<'a> {
495
495
None => {
496
496
let after_eq = eq. shrink_to_hi ( ) ;
497
497
let before_next = self . token . span . shrink_to_lo ( ) ;
498
- self . struct_span_err ( after_eq. to ( before_next) , "missing type to the right of `=`" )
499
- . span_suggestion (
498
+ let mut err = self
499
+ . struct_span_err ( after_eq. to ( before_next) , "missing type to the right of `=`" ) ;
500
+ if matches ! ( self . token. kind, token:: Comma | token:: Gt ) {
501
+ err. span_suggestion (
500
502
self . sess . source_map ( ) . next_point ( eq) . to ( before_next) ,
501
503
"to constrain the associated type, add a type after `=`" ,
502
504
" TheType" . to_string ( ) ,
503
505
Applicability :: HasPlaceholders ,
504
- )
505
- . span_suggestion (
506
+ ) ;
507
+ err . span_suggestion (
506
508
eq. to ( before_next) ,
507
509
& format ! ( "remove the `=` if `{}` is a type" , ident) ,
508
510
String :: new ( ) ,
509
511
Applicability :: MaybeIncorrect ,
510
512
)
511
- . emit ( ) ;
513
+ } else {
514
+ err. span_label (
515
+ self . token . span ,
516
+ & format ! ( "expected type, found {}" , super :: token_descr( & self . token) ) ,
517
+ )
518
+ } ;
519
+ return Err ( err) ;
512
520
}
513
521
}
514
522
Ok ( self . mk_ty ( span, ast:: TyKind :: Err ) )
@@ -572,6 +580,25 @@ impl<'a> Parser<'a> {
572
580
return self . recover_const_arg ( start, err) . map ( Some ) ;
573
581
}
574
582
}
583
+ } else if self . eat_keyword_noexpect ( kw:: Const ) {
584
+ // Detect and recover from the old, pre-RFC2000 syntax for const generics.
585
+ let mut err = self . struct_span_err (
586
+ start,
587
+ "expected lifetime, type, or constant, found keyword `const`" ,
588
+ ) ;
589
+ if self . check_const_arg ( ) {
590
+ err. span_suggestion_verbose (
591
+ start. until ( self . token . span ) ,
592
+ "the `const` keyword is only needed in the definition of the type" ,
593
+ String :: new ( ) ,
594
+ Applicability :: MaybeIncorrect ,
595
+ ) ;
596
+ err. emit ( ) ;
597
+ GenericArg :: Const ( self . parse_const_arg ( ) ?)
598
+ } else {
599
+ let after_kw_const = self . token . span ;
600
+ return self . recover_const_arg ( after_kw_const, err) . map ( Some ) ;
601
+ }
575
602
} else {
576
603
return Ok ( None ) ;
577
604
} ;
0 commit comments