@@ -1088,32 +1088,50 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1088
1088
AssocConstraintKind :: Bound { bounds } => {
1089
1089
enum DesugarKind {
1090
1090
ImplTrait ,
1091
- Error ,
1091
+ Error ( Option < Span > ) ,
1092
1092
Bound ,
1093
1093
}
1094
1094
1095
1095
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
1096
- let desugar_kind = match itctx {
1097
- _ if self . is_in_dyn_type => DesugarKind :: Error ,
1098
-
1099
- // We are in the return position:
1100
- //
1101
- // fn foo() -> impl Iterator<Item: Debug>
1102
- //
1103
- // so desugar to
1104
- //
1105
- // fn foo() -> impl Iterator<Item = impl Debug>
1106
- ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1107
- | ImplTraitContext :: TypeAliasesOpaqueTy { .. } => DesugarKind :: ImplTrait ,
1108
-
1109
- // We are in the parameter position, but not within a dyn type:
1110
- //
1111
- // fn foo(x: impl Iterator<Item: Debug>)
1112
- //
1113
- // so we leave it as is and this gets expanded in astconv to a bound like
1114
- // `<T as Iterator>::Item: Debug` where `T` is the type parameter for the
1115
- // `impl Iterator`.
1116
- _ => DesugarKind :: Bound ,
1096
+ let desugar_kind = if self . is_in_dyn_type {
1097
+ match itctx {
1098
+ ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1099
+ | ImplTraitContext :: TypeAliasesOpaqueTy { .. }
1100
+ | ImplTraitContext :: Universal => {
1101
+ let bound_end_span = constraint
1102
+ . gen_args
1103
+ . as_ref ( )
1104
+ . map_or ( constraint. ident . span , |args| args. span ( ) ) ;
1105
+ let colon_span = if bound_end_span. eq_ctxt ( constraint. span ) {
1106
+ Some ( self . tcx . sess . source_map ( ) . next_point ( bound_end_span) )
1107
+ } else {
1108
+ None
1109
+ } ;
1110
+ DesugarKind :: Error ( colon_span)
1111
+ }
1112
+ _ => DesugarKind :: Error ( None ) ,
1113
+ }
1114
+ } else {
1115
+ match itctx {
1116
+ // We are in the return position:
1117
+ //
1118
+ // fn foo() -> impl Iterator<Item: Debug>
1119
+ //
1120
+ // so desugar to
1121
+ //
1122
+ // fn foo() -> impl Iterator<Item = impl Debug>
1123
+ ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1124
+ | ImplTraitContext :: TypeAliasesOpaqueTy { .. } => DesugarKind :: ImplTrait ,
1125
+
1126
+ // We are in the parameter position, but not within a dyn type:
1127
+ //
1128
+ // fn foo(x: impl Iterator<Item: Debug>)
1129
+ //
1130
+ // so we leave it as is and this gets expanded in astconv to a bound like
1131
+ // `<T as Iterator>::Item: Debug` where `T` is the type parameter for the
1132
+ // `impl Iterator`.
1133
+ _ => DesugarKind :: Bound ,
1134
+ }
1117
1135
} ;
1118
1136
1119
1137
match desugar_kind {
@@ -1150,10 +1168,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1150
1168
1151
1169
hir:: TypeBindingKind :: Constraint { bounds }
1152
1170
}
1153
- DesugarKind :: Error => {
1154
- let guar = self
1155
- . dcx ( )
1156
- . emit_err ( errors:: MisplacedAssocTyBinding { span : constraint. span } ) ;
1171
+ DesugarKind :: Error ( suggestion) => {
1172
+ let guar = self . dcx ( ) . emit_err ( errors:: MisplacedAssocTyBinding {
1173
+ span : constraint. span ,
1174
+ suggestion,
1175
+ } ) ;
1157
1176
let err_ty =
1158
1177
& * self . arena . alloc ( self . ty ( constraint. span , hir:: TyKind :: Err ( guar) ) ) ;
1159
1178
hir:: TypeBindingKind :: Equality { term : err_ty. into ( ) }
0 commit comments