@@ -495,25 +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
- let the_type_placeholder = if matches ! ( self . token. kind, token:: Comma | token:: Gt ) {
499
- " TheType"
500
- } else {
501
- " TheType "
502
- } ;
503
- self . struct_span_err ( after_eq. to ( before_next) , "missing type to the right of `=`" )
504
- . 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 (
505
502
self . sess . source_map ( ) . next_point ( eq) . to ( before_next) ,
506
503
"to constrain the associated type, add a type after `=`" ,
507
- the_type_placeholder . to_string ( ) ,
504
+ " TheType" . to_string ( ) ,
508
505
Applicability :: HasPlaceholders ,
509
- )
510
- . span_suggestion (
506
+ ) ;
507
+ err . span_suggestion (
511
508
eq. to ( before_next) ,
512
509
& format ! ( "remove the `=` if `{}` is a type" , ident) ,
513
510
String :: new ( ) ,
514
511
Applicability :: MaybeIncorrect ,
515
512
)
516
- . 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) ;
517
520
}
518
521
}
519
522
Ok ( self . mk_ty ( span, ast:: TyKind :: Err ) )
@@ -584,6 +587,12 @@ impl<'a> Parser<'a> {
584
587
"expected lifetime, type, or constant, found keyword `const`" ,
585
588
) ;
586
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
+ ) ;
587
596
err. emit ( ) ;
588
597
GenericArg :: Const ( self . parse_const_arg ( ) ?)
589
598
} else {
0 commit comments