@@ -184,21 +184,17 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
184184 if !tcx. features ( ) . effects {
185185 return None ;
186186 }
187- match tcx. def_kind ( def_id) {
187+ let ( feed , parent_did ) = match tcx. def_kind ( def_id) {
188188 DefKind :: Trait => {
189189 let trait_def_id = def_id;
190- let Some ( attr) = tcx. get_attr ( def_id, sym:: const_trait) else {
191- return None ;
192- } ;
190+ let attr = tcx. get_attr ( def_id, sym:: const_trait) ?;
193191
194192 let span = attr. span ;
195193 let trait_assoc_ty = tcx. at ( span) . create_def ( trait_def_id, kw:: Empty , DefKind :: AssocTy ) ;
196194
197195 let local_def_id = trait_assoc_ty. def_id ( ) ;
198196 let def_id = local_def_id. to_def_id ( ) ;
199197
200- trait_assoc_ty. feed_hir ( ) ;
201-
202198 // Copy span of the attribute.
203199 trait_assoc_ty. def_ident_span ( Some ( span) ) ;
204200
@@ -213,47 +209,20 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
213209 is_effects_desugaring : true ,
214210 } ) ;
215211
216- // visibility is public.
217- trait_assoc_ty. visibility ( ty:: Visibility :: Public ) ;
218-
219212 // No default type
220213 trait_assoc_ty. defaultness ( hir:: Defaultness :: Default { has_value : false } ) ;
221214
222215 trait_assoc_ty. is_type_alias_impl_trait ( false ) ;
223216
224- // Copy generics_of of the trait, making the trait as parent.
225- trait_assoc_ty. generics_of ( {
226- let parent_generics = tcx. generics_of ( trait_def_id) ;
227- let parent_count = parent_generics. parent_count + parent_generics. own_params . len ( ) ;
228-
229- ty:: Generics {
230- parent : Some ( trait_def_id. to_def_id ( ) ) ,
231- parent_count,
232- own_params : vec ! [ ] ,
233- param_def_id_to_index : parent_generics. param_def_id_to_index . clone ( ) ,
234- has_self : false ,
235- has_late_bound_regions : None ,
236- host_effect_index : parent_generics. host_effect_index ,
237- }
238- } ) ;
239-
240- trait_assoc_ty. explicit_item_bounds ( ty:: EarlyBinder :: bind ( & [ ] ) ) ;
241- trait_assoc_ty. explicit_item_super_predicates ( ty:: EarlyBinder :: bind ( & [ ] ) ) ;
242-
243- // There are no inferred outlives for the synthesized associated type.
244- trait_assoc_ty. inferred_outlives_of ( & [ ] ) ;
245-
246- Some ( def_id)
217+ ( trait_assoc_ty, trait_def_id)
247218 }
248219 DefKind :: Impl { .. } => {
249220 let impl_def_id = def_id;
250- let Some ( trait_id) = tcx. trait_id_of_impl ( def_id. to_def_id ( ) ) else { return None } ;
221+ let trait_id = tcx. trait_id_of_impl ( def_id. to_def_id ( ) ) ? ;
251222
252223 // first get the DefId of the assoc type on the trait, if there is not,
253224 // then we don't need to generate it on the impl.
254- let Some ( trait_assoc_id) = tcx. associated_type_for_effects ( trait_id) else {
255- return None ;
256- } ;
225+ let trait_assoc_id = tcx. associated_type_for_effects ( trait_id) ?;
257226
258227 // FIXME(effects): span
259228 let span = tcx. def_ident_span ( def_id) . unwrap ( ) ;
@@ -263,8 +232,6 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
263232 let local_def_id = impl_assoc_ty. def_id ( ) ;
264233 let def_id = local_def_id. to_def_id ( ) ;
265234
266- impl_assoc_ty. feed_hir ( ) ;
267-
268235 impl_assoc_ty. def_ident_span ( Some ( span) ) ;
269236
270237 impl_assoc_ty. associated_item ( ty:: AssocItem {
@@ -278,9 +245,6 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
278245 is_effects_desugaring : true ,
279246 } ) ;
280247
281- // visibility is public.
282- impl_assoc_ty. visibility ( ty:: Visibility :: Public ) ;
283-
284248 // no default value.
285249 impl_assoc_ty. defaultness ( hir:: Defaultness :: Final ) ;
286250
@@ -298,36 +262,41 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
298262 ty:: GenericArgs :: empty ( ) ,
299263 ) ) ) ;
300264
301- // Copy generics_of of the impl, making the impl as parent.
302- impl_assoc_ty. generics_of ( {
303- let parent_generics = tcx. generics_of ( impl_def_id) ;
304- let parent_count = parent_generics. parent_count + parent_generics. own_params . len ( ) ;
305-
306- ty:: Generics {
307- parent : Some ( impl_def_id. to_def_id ( ) ) ,
308- parent_count,
309- own_params : vec ! [ ] ,
310- param_def_id_to_index : parent_generics. param_def_id_to_index . clone ( ) ,
311- has_self : false ,
312- has_late_bound_regions : None ,
313- host_effect_index : parent_generics. host_effect_index ,
314- }
315- } ) ;
316-
317- // impl_assoc_ty.explicit_item_bounds(ty::EarlyBinder::bind(&[]));
318- impl_assoc_ty. explicit_item_super_predicates ( ty:: EarlyBinder :: bind ( & [ ] ) ) ;
319-
320- // There are no inferred outlives for the synthesized associated type.
321- impl_assoc_ty. inferred_outlives_of ( & [ ] ) ;
322-
323- Some ( def_id)
265+ ( impl_assoc_ty, impl_def_id)
324266 }
325267 def_kind => bug ! (
326268 "associated_type_for_effects: {:?} should be Trait or Impl but is {:?}" ,
327269 def_id,
328270 def_kind
329271 ) ,
330- }
272+ } ;
273+
274+ feed. feed_hir ( ) ;
275+
276+ // visibility is public.
277+ feed. visibility ( ty:: Visibility :: Public ) ;
278+
279+ // Copy generics_of of the trait/impl, making the trait/impl as parent.
280+ feed. generics_of ( {
281+ let parent_generics = tcx. generics_of ( parent_did) ;
282+ let parent_count = parent_generics. parent_count + parent_generics. own_params . len ( ) ;
283+
284+ ty:: Generics {
285+ parent : Some ( parent_did. to_def_id ( ) ) ,
286+ parent_count,
287+ own_params : vec ! [ ] ,
288+ param_def_id_to_index : parent_generics. param_def_id_to_index . clone ( ) ,
289+ has_self : false ,
290+ has_late_bound_regions : None ,
291+ host_effect_index : parent_generics. host_effect_index ,
292+ }
293+ } ) ;
294+ feed. explicit_item_super_predicates ( ty:: EarlyBinder :: bind ( & [ ] ) ) ;
295+
296+ // There are no inferred outlives for the synthesized associated type.
297+ feed. inferred_outlives_of ( & [ ] ) ;
298+
299+ Some ( feed. def_id ( ) . to_def_id ( ) )
331300}
332301
333302/// Given an `fn_def_id` of a trait or a trait implementation:
0 commit comments