@@ -208,8 +208,8 @@ where
208
208
// available to downstream crates. This depends on whether we are in
209
209
// share-generics mode and whether the current crate can even have
210
210
// downstream crates.
211
- let export_generics =
212
- cx. tcx . sess . opts . share_generics ( ) && cx . tcx . local_crate_exports_generics ( ) ;
211
+ let can_export_generics = cx . tcx . local_crate_exports_generics ( ) ;
212
+ let always_export_generics = can_export_generics && cx. tcx . sess . opts . share_generics ( ) ;
213
213
214
214
let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx. tcx ) ;
215
215
let cgu_name_cache = & mut UnordMap :: default ( ) ;
@@ -249,7 +249,8 @@ where
249
249
cx. tcx ,
250
250
& mono_item,
251
251
& mut can_be_internalized,
252
- export_generics,
252
+ can_export_generics,
253
+ always_export_generics,
253
254
) ;
254
255
if visibility == Visibility :: Hidden && can_be_internalized {
255
256
internalization_candidates. insert ( mono_item) ;
@@ -739,12 +740,19 @@ fn mono_item_linkage_and_visibility<'tcx>(
739
740
tcx : TyCtxt < ' tcx > ,
740
741
mono_item : & MonoItem < ' tcx > ,
741
742
can_be_internalized : & mut bool ,
742
- export_generics : bool ,
743
+ can_export_generics : bool ,
744
+ always_export_generics : bool ,
743
745
) -> ( Linkage , Visibility ) {
744
746
if let Some ( explicit_linkage) = mono_item. explicit_linkage ( tcx) {
745
747
return ( explicit_linkage, Visibility :: Default ) ;
746
748
}
747
- let vis = mono_item_visibility ( tcx, mono_item, can_be_internalized, export_generics) ;
749
+ let vis = mono_item_visibility (
750
+ tcx,
751
+ mono_item,
752
+ can_be_internalized,
753
+ can_export_generics,
754
+ always_export_generics,
755
+ ) ;
748
756
( Linkage :: External , vis)
749
757
}
750
758
@@ -767,7 +775,8 @@ fn mono_item_visibility<'tcx>(
767
775
tcx : TyCtxt < ' tcx > ,
768
776
mono_item : & MonoItem < ' tcx > ,
769
777
can_be_internalized : & mut bool ,
770
- export_generics : bool ,
778
+ can_export_generics : bool ,
779
+ always_export_generics : bool ,
771
780
) -> Visibility {
772
781
let instance = match mono_item {
773
782
// This is pretty complicated; see below.
@@ -826,7 +835,11 @@ fn mono_item_visibility<'tcx>(
826
835
827
836
// Upstream `DefId` instances get different handling than local ones.
828
837
let Some ( def_id) = def_id. as_local ( ) else {
829
- return if export_generics && is_generic {
838
+ return if is_generic
839
+ && ( always_export_generics
840
+ || ( can_export_generics
841
+ && tcx. codegen_fn_attrs ( def_id) . inline == rustc_attr:: InlineAttr :: Never ) )
842
+ {
830
843
// If it is an upstream monomorphization and we export generics, we must make
831
844
// it available to downstream crates.
832
845
* can_be_internalized = false ;
@@ -837,7 +850,10 @@ fn mono_item_visibility<'tcx>(
837
850
} ;
838
851
839
852
if is_generic {
840
- if export_generics {
853
+ if always_export_generics
854
+ || ( can_export_generics
855
+ && tcx. codegen_fn_attrs ( def_id) . inline == rustc_attr:: InlineAttr :: Never )
856
+ {
841
857
if tcx. is_unreachable_local_definition ( def_id) {
842
858
// This instance cannot be used from another crate.
843
859
Visibility :: Hidden
0 commit comments