@@ -184,21 +184,17 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
184
184
if !tcx. features ( ) . effects {
185
185
return None ;
186
186
}
187
- match tcx. def_kind ( def_id) {
187
+ let ( feed , parent_did ) = match tcx. def_kind ( def_id) {
188
188
DefKind :: Trait => {
189
189
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) ?;
193
191
194
192
let span = attr. span ;
195
193
let trait_assoc_ty = tcx. at ( span) . create_def ( trait_def_id, kw:: Empty , DefKind :: AssocTy ) ;
196
194
197
195
let local_def_id = trait_assoc_ty. def_id ( ) ;
198
196
let def_id = local_def_id. to_def_id ( ) ;
199
197
200
- trait_assoc_ty. feed_hir ( ) ;
201
-
202
198
// Copy span of the attribute.
203
199
trait_assoc_ty. def_ident_span ( Some ( span) ) ;
204
200
@@ -213,47 +209,20 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
213
209
is_effects_desugaring : true ,
214
210
} ) ;
215
211
216
- // visibility is public.
217
- trait_assoc_ty. visibility ( ty:: Visibility :: Public ) ;
218
-
219
212
// No default type
220
213
trait_assoc_ty. defaultness ( hir:: Defaultness :: Default { has_value : false } ) ;
221
214
222
215
trait_assoc_ty. is_type_alias_impl_trait ( false ) ;
223
216
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)
247
218
}
248
219
DefKind :: Impl { .. } => {
249
220
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 ( ) ) ? ;
251
222
252
223
// first get the DefId of the assoc type on the trait, if there is not,
253
224
// 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) ?;
257
226
258
227
// FIXME(effects): span
259
228
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
263
232
let local_def_id = impl_assoc_ty. def_id ( ) ;
264
233
let def_id = local_def_id. to_def_id ( ) ;
265
234
266
- impl_assoc_ty. feed_hir ( ) ;
267
-
268
235
impl_assoc_ty. def_ident_span ( Some ( span) ) ;
269
236
270
237
impl_assoc_ty. associated_item ( ty:: AssocItem {
@@ -278,9 +245,6 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
278
245
is_effects_desugaring : true ,
279
246
} ) ;
280
247
281
- // visibility is public.
282
- impl_assoc_ty. visibility ( ty:: Visibility :: Public ) ;
283
-
284
248
// no default value.
285
249
impl_assoc_ty. defaultness ( hir:: Defaultness :: Final ) ;
286
250
@@ -298,36 +262,41 @@ fn associated_type_for_effects(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<De
298
262
ty:: GenericArgs :: empty ( ) ,
299
263
) ) ) ;
300
264
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)
324
266
}
325
267
def_kind => bug ! (
326
268
"associated_type_for_effects: {:?} should be Trait or Impl but is {:?}" ,
327
269
def_id,
328
270
def_kind
329
271
) ,
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 ( ) )
331
300
}
332
301
333
302
/// Given an `fn_def_id` of a trait or a trait implementation:
0 commit comments