@@ -1191,28 +1191,14 @@ impl<'v> RootCollector<'_, 'v> {
1191
1191
fn process_item ( & mut self , id : hir:: ItemId ) {
1192
1192
match self . tcx . def_kind ( id. owner_id ) {
1193
1193
DefKind :: Enum | DefKind :: Struct | DefKind :: Union => {
1194
- let item = self . tcx . hir ( ) . item ( id) ;
1195
- match item. kind {
1196
- hir:: ItemKind :: Enum ( _, ref generics)
1197
- | hir:: ItemKind :: Struct ( _, ref generics)
1198
- | hir:: ItemKind :: Union ( _, ref generics) => {
1199
- if generics. params . is_empty ( ) {
1200
- if self . mode == MonoItemCollectionMode :: Eager {
1201
- debug ! (
1202
- "RootCollector: ADT drop-glue for {}" ,
1203
- self . tcx. def_path_str( item. owner_id. to_def_id( ) )
1204
- ) ;
1205
-
1206
- let ty = Instance :: new (
1207
- item. owner_id . to_def_id ( ) ,
1208
- InternalSubsts :: empty ( ) ,
1209
- )
1210
- . ty ( self . tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
1211
- visit_drop_use ( self . tcx , ty, true , DUMMY_SP , self . output ) ;
1212
- }
1213
- }
1214
- }
1215
- _ => bug ! ( ) ,
1194
+ if self . tcx . generics_of ( id. owner_id ) . count ( ) == 0
1195
+ && self . mode == MonoItemCollectionMode :: Eager
1196
+ {
1197
+ debug ! ( "RootCollector: ADT drop-glue for `{id:?}`" , ) ;
1198
+
1199
+ let ty =
1200
+ self . tcx . bound_type_of ( id. owner_id . to_def_id ( ) ) . no_bound_vars ( ) . unwrap ( ) ;
1201
+ visit_drop_use ( self . tcx , ty, true , DUMMY_SP , self . output ) ;
1216
1202
}
1217
1203
}
1218
1204
DefKind :: GlobalAsm => {
@@ -1240,8 +1226,7 @@ impl<'v> RootCollector<'_, 'v> {
1240
1226
}
1241
1227
DefKind :: Impl { .. } => {
1242
1228
if self . mode == MonoItemCollectionMode :: Eager {
1243
- let item = self . tcx . hir ( ) . item ( id) ;
1244
- create_mono_items_for_default_impls ( self . tcx , item, self . output ) ;
1229
+ create_mono_items_for_default_impls ( self . tcx , id, self . output ) ;
1245
1230
}
1246
1231
}
1247
1232
DefKind :: Fn => {
@@ -1326,66 +1311,51 @@ fn item_requires_monomorphization(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1326
1311
generics. requires_monomorphization ( tcx)
1327
1312
}
1328
1313
1314
+ #[ instrument( level = "debug" , skip( tcx, output) ) ]
1329
1315
fn create_mono_items_for_default_impls < ' tcx > (
1330
1316
tcx : TyCtxt < ' tcx > ,
1331
- item : & ' tcx hir:: Item < ' tcx > ,
1317
+ item : hir:: ItemId ,
1332
1318
output : & mut MonoItems < ' tcx > ,
1333
1319
) {
1334
- match item. kind {
1335
- hir:: ItemKind :: Impl ( ref impl_) => {
1336
- if matches ! ( impl_. polarity, hir:: ImplPolarity :: Negative ( _) ) {
1337
- return ;
1338
- }
1320
+ let polarity = tcx. impl_polarity ( item. owner_id ) ;
1321
+ if matches ! ( polarity, ty:: ImplPolarity :: Negative ) {
1322
+ return ;
1323
+ }
1339
1324
1340
- for param in impl_. generics . params {
1341
- match param. kind {
1342
- hir:: GenericParamKind :: Lifetime { .. } => { }
1343
- hir:: GenericParamKind :: Type { .. } | hir:: GenericParamKind :: Const { .. } => {
1344
- return ;
1345
- }
1346
- }
1347
- }
1325
+ if tcx. generics_of ( item. owner_id ) . own_requires_monomorphization ( ) {
1326
+ return ;
1327
+ }
1348
1328
1349
- debug ! (
1350
- "create_mono_items_for_default_impls(item={})" ,
1351
- tcx. def_path_str( item. owner_id. to_def_id( ) )
1352
- ) ;
1329
+ let Some ( trait_ref) = tcx. impl_trait_ref ( item. owner_id ) else {
1330
+ return ;
1331
+ } ;
1353
1332
1354
- if let Some ( trait_ref) = tcx. impl_trait_ref ( item. owner_id ) {
1355
- let trait_ref = trait_ref. subst_identity ( ) ;
1333
+ let trait_ref = trait_ref. subst_identity ( ) ;
1356
1334
1357
- let param_env = ty:: ParamEnv :: reveal_all ( ) ;
1358
- let trait_ref = tcx. normalize_erasing_regions ( param_env, trait_ref) ;
1359
- let overridden_methods = tcx. impl_item_implementor_ids ( item. owner_id ) ;
1360
- for method in tcx. provided_trait_methods ( trait_ref. def_id ) {
1361
- if overridden_methods. contains_key ( & method. def_id ) {
1362
- continue ;
1363
- }
1335
+ let param_env = ty:: ParamEnv :: reveal_all ( ) ;
1336
+ let trait_ref = tcx. normalize_erasing_regions ( param_env, trait_ref) ;
1337
+ let overridden_methods = tcx. impl_item_implementor_ids ( item. owner_id ) ;
1338
+ for method in tcx. provided_trait_methods ( trait_ref. def_id ) {
1339
+ if overridden_methods. contains_key ( & method. def_id ) {
1340
+ continue ;
1341
+ }
1364
1342
1365
- if tcx. generics_of ( method. def_id ) . own_requires_monomorphization ( ) {
1366
- continue ;
1367
- }
1343
+ if tcx. generics_of ( method. def_id ) . own_requires_monomorphization ( ) {
1344
+ continue ;
1345
+ }
1368
1346
1369
- let substs =
1370
- InternalSubsts :: for_item ( tcx, method. def_id , |param, _| match param. kind {
1371
- GenericParamDefKind :: Lifetime => tcx. lifetimes . re_erased . into ( ) ,
1372
- GenericParamDefKind :: Type { .. }
1373
- | GenericParamDefKind :: Const { .. } => {
1374
- trait_ref. substs [ param. index as usize ]
1375
- }
1376
- } ) ;
1377
- let instance =
1378
- ty:: Instance :: expect_resolve ( tcx, param_env, method. def_id , substs) ;
1379
-
1380
- let mono_item = create_fn_mono_item ( tcx, instance, DUMMY_SP ) ;
1381
- if mono_item. node . is_instantiable ( tcx) && should_codegen_locally ( tcx, & instance)
1382
- {
1383
- output. push ( mono_item) ;
1384
- }
1385
- }
1347
+ let substs = InternalSubsts :: for_item ( tcx, method. def_id , |param, _| match param. kind {
1348
+ GenericParamDefKind :: Lifetime => tcx. lifetimes . re_erased . into ( ) ,
1349
+ GenericParamDefKind :: Type { .. } | GenericParamDefKind :: Const { .. } => {
1350
+ trait_ref. substs [ param. index as usize ]
1386
1351
}
1352
+ } ) ;
1353
+ let instance = ty:: Instance :: expect_resolve ( tcx, param_env, method. def_id , substs) ;
1354
+
1355
+ let mono_item = create_fn_mono_item ( tcx, instance, DUMMY_SP ) ;
1356
+ if mono_item. node . is_instantiable ( tcx) && should_codegen_locally ( tcx, & instance) {
1357
+ output. push ( mono_item) ;
1387
1358
}
1388
- _ => bug ! ( ) ,
1389
1359
}
1390
1360
}
1391
1361
0 commit comments