@@ -203,8 +203,8 @@ where
203
203
// available to downstream crates. This depends on whether we are in
204
204
// share-generics mode and whether the current crate can even have
205
205
// downstream crates.
206
- let export_generics =
207
- cx. tcx . sess . opts . share_generics ( ) && cx . tcx . local_crate_exports_generics ( ) ;
206
+ let can_export_generics = cx . tcx . local_crate_exports_generics ( ) ;
207
+ let always_export_generics = can_export_generics && cx. tcx . sess . opts . share_generics ( ) ;
208
208
209
209
let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx. tcx ) ;
210
210
let cgu_name_cache = & mut FxHashMap :: default ( ) ;
@@ -244,7 +244,8 @@ where
244
244
cx. tcx ,
245
245
& mono_item,
246
246
& mut can_be_internalized,
247
- export_generics,
247
+ can_export_generics,
248
+ always_export_generics,
248
249
) ;
249
250
if visibility == Visibility :: Hidden && can_be_internalized {
250
251
internalization_candidates. insert ( mono_item) ;
@@ -727,12 +728,19 @@ fn mono_item_linkage_and_visibility<'tcx>(
727
728
tcx : TyCtxt < ' tcx > ,
728
729
mono_item : & MonoItem < ' tcx > ,
729
730
can_be_internalized : & mut bool ,
730
- export_generics : bool ,
731
+ can_export_generics : bool ,
732
+ always_export_generics : bool ,
731
733
) -> ( Linkage , Visibility ) {
732
734
if let Some ( explicit_linkage) = mono_item. explicit_linkage ( tcx) {
733
735
return ( explicit_linkage, Visibility :: Default ) ;
734
736
}
735
- let vis = mono_item_visibility ( tcx, mono_item, can_be_internalized, export_generics) ;
737
+ let vis = mono_item_visibility (
738
+ tcx,
739
+ mono_item,
740
+ can_be_internalized,
741
+ can_export_generics,
742
+ always_export_generics,
743
+ ) ;
736
744
( Linkage :: External , vis)
737
745
}
738
746
@@ -755,7 +763,8 @@ fn mono_item_visibility<'tcx>(
755
763
tcx : TyCtxt < ' tcx > ,
756
764
mono_item : & MonoItem < ' tcx > ,
757
765
can_be_internalized : & mut bool ,
758
- export_generics : bool ,
766
+ can_export_generics : bool ,
767
+ always_export_generics : bool ,
759
768
) -> Visibility {
760
769
let instance = match mono_item {
761
770
// This is pretty complicated; see below.
@@ -812,7 +821,11 @@ fn mono_item_visibility<'tcx>(
812
821
813
822
// Upstream `DefId` instances get different handling than local ones.
814
823
let Some ( def_id) = def_id. as_local ( ) else {
815
- return if export_generics && is_generic {
824
+ return if is_generic
825
+ && ( always_export_generics
826
+ || ( can_export_generics
827
+ && tcx. codegen_fn_attrs ( def_id) . inline == rustc_attr:: InlineAttr :: Never ) )
828
+ {
816
829
// If it is an upstream monomorphization and we export generics, we must make
817
830
// it available to downstream crates.
818
831
* can_be_internalized = false ;
@@ -823,7 +836,12 @@ fn mono_item_visibility<'tcx>(
823
836
} ;
824
837
825
838
if is_generic {
826
- if export_generics {
839
+ // An inline(never) function won't get inlined in upstream crates anyway, so we might as
840
+ // well export it.
841
+ if always_export_generics
842
+ || ( can_export_generics
843
+ && tcx. codegen_fn_attrs ( def_id) . inline == rustc_attr:: InlineAttr :: Never )
844
+ {
827
845
if tcx. is_unreachable_local_definition ( def_id) {
828
846
// This instance cannot be used from another crate.
829
847
Visibility :: Hidden
0 commit comments