@@ -197,7 +197,6 @@ trait ResolverAstLoweringExt {
197197 fn get_label_res ( & self , id : NodeId ) -> Option < NodeId > ;
198198 fn get_lifetime_res ( & self , id : NodeId ) -> Option < LifetimeRes > ;
199199 fn take_extra_lifetime_params ( & mut self , id : NodeId ) -> Vec < ( Ident , NodeId , LifetimeRes ) > ;
200- fn remap_extra_lifetime_params ( & mut self , from : NodeId , to : NodeId ) ;
201200}
202201
203202impl ResolverAstLoweringExt for ResolverAstLowering {
@@ -256,11 +255,6 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
256255 fn take_extra_lifetime_params ( & mut self , id : NodeId ) -> Vec < ( Ident , NodeId , LifetimeRes ) > {
257256 self . extra_lifetime_params_map . remove ( & id) . unwrap_or_default ( )
258257 }
259-
260- fn remap_extra_lifetime_params ( & mut self , from : NodeId , to : NodeId ) {
261- let lifetimes = self . extra_lifetime_params_map . remove ( & from) . unwrap_or_default ( ) ;
262- self . extra_lifetime_params_map . insert ( to, lifetimes) ;
263- }
264258}
265259
266260/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
@@ -1084,88 +1078,38 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10841078 hir:: TypeBindingKind :: Equality { term }
10851079 }
10861080 AssocConstraintKind :: Bound { bounds } => {
1087- enum DesugarKind {
1088- ImplTrait ,
1089- Error ( ImplTraitPosition ) ,
1090- Bound ,
1091- }
1092-
1093- // Piggy-back on the `impl Trait` context to figure out the correct behavior.
1094- let desugar_kind = match itctx {
1095- // in an argument, RPIT, or TAIT, if we are within a dyn type:
1096- //
1097- // fn foo(x: dyn Iterator<Item: Debug>)
1098- //
1099- // then desugar to:
1100- //
1101- // fn foo(x: dyn Iterator<Item = impl Debug>)
1102- //
1103- // This is because dyn traits must have all of their associated types specified.
1104- ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1105- | ImplTraitContext :: TypeAliasesOpaqueTy { .. }
1106- | ImplTraitContext :: Universal
1107- if self . is_in_dyn_type =>
1108- {
1109- DesugarKind :: ImplTrait
1110- }
1111-
1112- ImplTraitContext :: Disallowed ( position) if self . is_in_dyn_type => {
1113- DesugarKind :: Error ( position)
1114- }
1115-
1116- // We are in the parameter position, but not within a dyn type:
1117- //
1118- // fn foo(x: impl Iterator<Item: Debug>)
1119- //
1120- // so we leave it as is and this gets expanded in astconv to a bound like
1121- // `<T as Iterator>::Item: Debug` where `T` is the type parameter for the
1122- // `impl Iterator`.
1123- _ => DesugarKind :: Bound ,
1124- } ;
1125-
1126- match desugar_kind {
1127- DesugarKind :: ImplTrait => {
1128- // Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
1129- // constructing the HIR for `impl bounds...` and then lowering that.
1130-
1131- let impl_trait_node_id = self . next_node_id ( ) ;
1132- // Shift `impl Trait` lifetime captures from the associated type bound's
1133- // node id to the opaque node id, so that the opaque can actually use
1134- // these lifetime bounds.
1135- self . resolver
1136- . remap_extra_lifetime_params ( constraint. id , impl_trait_node_id) ;
1137-
1138- self . with_dyn_type_scope ( false , |this| {
1139- let node_id = this. next_node_id ( ) ;
1140- let ty = this. lower_ty (
1141- & Ty {
1142- id : node_id,
1143- kind : TyKind :: ImplTrait ( impl_trait_node_id, bounds. clone ( ) ) ,
1144- span : this. lower_span ( constraint. span ) ,
1145- tokens : None ,
1146- } ,
1147- itctx,
1148- ) ;
1081+ // Disallow ATB in dyn types
1082+ if self . is_in_dyn_type {
1083+ let suggestion = match itctx {
1084+ ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1085+ | ImplTraitContext :: TypeAliasesOpaqueTy { .. }
1086+ | ImplTraitContext :: Universal => {
1087+ let bound_end_span = constraint
1088+ . gen_args
1089+ . as_ref ( )
1090+ . map_or ( constraint. ident . span , |args| args. span ( ) ) ;
1091+ if bound_end_span. eq_ctxt ( constraint. span ) {
1092+ Some ( self . tcx . sess . source_map ( ) . next_point ( bound_end_span) )
1093+ } else {
1094+ None
1095+ }
1096+ }
1097+ _ => None ,
1098+ } ;
11491099
1150- hir:: TypeBindingKind :: Equality { term : ty. into ( ) }
1151- } )
1152- }
1153- DesugarKind :: Bound => {
1154- // Desugar `AssocTy: Bounds` into a type binding where the
1155- // later desugars into a trait predicate.
1156- let bounds = self . lower_param_bounds ( bounds, itctx) ;
1100+ let guar = self . dcx ( ) . emit_err ( errors:: MisplacedAssocTyBinding {
1101+ span : constraint. span ,
1102+ suggestion,
1103+ } ) ;
1104+ let err_ty =
1105+ & * self . arena . alloc ( self . ty ( constraint. span , hir:: TyKind :: Err ( guar) ) ) ;
1106+ hir:: TypeBindingKind :: Equality { term : err_ty. into ( ) }
1107+ } else {
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) ;
11571111
1158- hir:: TypeBindingKind :: Constraint { bounds }
1159- }
1160- DesugarKind :: Error ( position) => {
1161- let guar = self . dcx ( ) . emit_err ( errors:: MisplacedAssocTyBinding {
1162- span : constraint. span ,
1163- position : DiagnosticArgFromDisplay ( & position) ,
1164- } ) ;
1165- let err_ty =
1166- & * self . arena . alloc ( self . ty ( constraint. span , hir:: TyKind :: Err ( guar) ) ) ;
1167- hir:: TypeBindingKind :: Equality { term : err_ty. into ( ) }
1168- }
1112+ hir:: TypeBindingKind :: Constraint { bounds }
11691113 }
11701114 }
11711115 } ;
0 commit comments