@@ -1084,41 +1084,38 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1084
1084
hir:: TypeBindingKind :: Equality { term }
1085
1085
}
1086
1086
AssocConstraintKind :: Bound { bounds } => {
1087
- enum DesugarKind {
1088
- Error ,
1089
- Bound ,
1090
- }
1091
-
1092
- // Piggy-back on the `impl Trait` context to figure out the correct behavior.
1093
- let desugar_kind = match itctx {
1094
- _ if self . is_in_dyn_type => DesugarKind :: Error ,
1095
-
1096
- // We are in the parameter position, but not within a dyn type:
1097
- //
1098
- // fn foo(x: impl Iterator<Item: Debug> )
1099
- //
1100
- // so we leave it as is and this gets expanded in astconv to a bound like
1101
- // `<T as Iterator>::Item: Debug` where `T` is the type parameter for the
1102
- // `impl Iterator`.
1103
- _ => DesugarKind :: Bound ,
1104
- } ;
1087
+ // Disallow ATB in dyn types
1088
+ if self . is_in_dyn_type {
1089
+ let suggestion = match itctx {
1090
+ ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1091
+ | ImplTraitContext :: TypeAliasesOpaqueTy { .. }
1092
+ | ImplTraitContext :: Universal => {
1093
+ let bound_end_span = constraint
1094
+ . gen_args
1095
+ . as_ref ( )
1096
+ . map_or ( constraint . ident . span , |args| args . span ( ) ) ;
1097
+ if bound_end_span . eq_ctxt ( constraint . span ) {
1098
+ Some ( self . tcx . sess . source_map ( ) . next_point ( bound_end_span ) )
1099
+ } else {
1100
+ None
1101
+ }
1102
+ }
1103
+ _ => None ,
1104
+ } ;
1105
1105
1106
- match desugar_kind {
1107
- DesugarKind :: Bound => {
1108
- // Desugar `AssocTy: Bounds` into a type binding where the
1109
- // later desugars into a trait predicate.
1110
- let bounds = self . lower_param_bounds ( bounds, itctx) ;
1106
+ let guar = self . dcx ( ) . emit_err ( errors:: MisplacedAssocTyBinding {
1107
+ span : constraint. span ,
1108
+ suggestion,
1109
+ } ) ;
1110
+ let err_ty =
1111
+ & * self . arena . alloc ( self . ty ( constraint. span , hir:: TyKind :: Err ( guar) ) ) ;
1112
+ hir:: TypeBindingKind :: Equality { term : err_ty. into ( ) }
1113
+ } else {
1114
+ // Desugar `AssocTy: Bounds` into a type binding where the
1115
+ // later desugars into a trait predicate.
1116
+ let bounds = self . lower_param_bounds ( bounds, itctx) ;
1111
1117
1112
- hir:: TypeBindingKind :: Constraint { bounds }
1113
- }
1114
- DesugarKind :: Error => {
1115
- let guar = self
1116
- . dcx ( )
1117
- . emit_err ( errors:: MisplacedAssocTyBinding { span : constraint. span } ) ;
1118
- let err_ty =
1119
- & * self . arena . alloc ( self . ty ( constraint. span , hir:: TyKind :: Err ( guar) ) ) ;
1120
- hir:: TypeBindingKind :: Equality { term : err_ty. into ( ) }
1121
- }
1118
+ hir:: TypeBindingKind :: Constraint { bounds }
1122
1119
}
1123
1120
}
1124
1121
} ;
0 commit comments