@@ -626,7 +626,11 @@ impl<'a> Parser<'a> {
626
626
let bounds = self . parse_generic_bounds ( ) ?;
627
627
AssocConstraintKind :: Bound { bounds }
628
628
} else if self . eat ( & token:: Eq ) {
629
- self . parse_assoc_equality_term ( ident, self . prev_token . span ) ?
629
+ self . parse_assoc_equality_term (
630
+ ident,
631
+ gen_args. as_ref ( ) ,
632
+ self . prev_token . span ,
633
+ ) ?
630
634
} else {
631
635
unreachable ! ( ) ;
632
636
} ;
@@ -663,11 +667,13 @@ impl<'a> Parser<'a> {
663
667
}
664
668
665
669
/// Parse the term to the right of an associated item equality constraint.
666
- /// That is, parse `<term>` in `Item = <term>`.
667
- /// Right now, this only admits types in `<term>`.
670
+ ///
671
+ /// That is, parse `$term` in `Item = $term` where `$term` is a type or
672
+ /// a const expression (wrapped in curly braces if complex).
668
673
fn parse_assoc_equality_term (
669
674
& mut self ,
670
675
ident : Ident ,
676
+ gen_args : Option < & GenericArgs > ,
671
677
eq : Span ,
672
678
) -> PResult < ' a , AssocConstraintKind > {
673
679
let arg = self . parse_generic_arg ( None ) ?;
@@ -679,9 +685,15 @@ impl<'a> Parser<'a> {
679
685
c. into ( )
680
686
}
681
687
Some ( GenericArg :: Lifetime ( lt) ) => {
682
- let guar =
683
- self . dcx ( ) . emit_err ( errors:: AssocLifetime { span, lifetime : lt. ident . span } ) ;
684
- self . mk_ty ( span, ast:: TyKind :: Err ( guar) ) . into ( )
688
+ let guar = self . dcx ( ) . emit_err ( errors:: LifetimeInEqConstraint {
689
+ span : lt. ident . span ,
690
+ lifetime : lt. ident ,
691
+ binding_label : span,
692
+ colon_sugg : gen_args
693
+ . map_or ( ident. span , |args| args. span ( ) )
694
+ . between ( lt. ident . span ) ,
695
+ } ) ;
696
+ self . mk_ty ( lt. ident . span , ast:: TyKind :: Err ( guar) ) . into ( )
685
697
}
686
698
None => {
687
699
let after_eq = eq. shrink_to_hi ( ) ;
0 commit comments