@@ -965,24 +965,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
965
965
return true ;
966
966
}
967
967
968
- if tcx. is_reachable_non_generic ( def_id) || instance. upstream_monomorphization ( * tcx) . is_some ( ) {
969
- // We can link to the item in question, no instance needed in this crate.
970
- return false ;
971
- }
972
-
973
- if let DefKind :: Static { .. } = tcx. def_kind ( def_id) {
974
- // We cannot monomorphize statics from upstream crates.
975
- return false ;
976
- }
977
-
978
- if !tcx. is_mir_available ( def_id) {
979
- tcx. dcx ( ) . emit_fatal ( NoOptimizedMir {
980
- span : tcx. def_span ( def_id) ,
981
- crate_name : tcx. crate_name ( def_id. krate ) ,
982
- } ) ;
983
- }
984
-
985
- true
968
+ tcx. should_codegen_locally_slow ( instance)
986
969
}
987
970
988
971
/// For a given pair of source and target type that occur in an unsizing coercion,
@@ -1643,4 +1626,26 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
1643
1626
pub ( crate ) fn provide ( providers : & mut Providers ) {
1644
1627
providers. hooks . should_codegen_locally = should_codegen_locally;
1645
1628
providers. items_of_instance = items_of_instance;
1629
+ providers. should_codegen_locally_slow = |tcx, instance| {
1630
+ let def_id = instance. def_id ( ) ;
1631
+ if let DefKind :: Static { .. } = tcx. def_kind ( def_id) {
1632
+ // We cannot monomorphize statics from upstream crates.
1633
+ return false ;
1634
+ }
1635
+
1636
+ if tcx. is_reachable_non_generic ( def_id) || instance. upstream_monomorphization ( tcx) . is_some ( )
1637
+ {
1638
+ // We can link to the item in question, no instance needed in this crate.
1639
+ return false ;
1640
+ }
1641
+
1642
+ if !tcx. is_mir_available ( def_id) {
1643
+ tcx. dcx ( ) . emit_fatal ( NoOptimizedMir {
1644
+ span : tcx. def_span ( def_id) ,
1645
+ crate_name : tcx. crate_name ( def_id. krate ) ,
1646
+ } ) ;
1647
+ }
1648
+
1649
+ true
1650
+ } ;
1646
1651
}
0 commit comments