File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed
compiler/rustc_monomorphize/src
tests/codegen-units/partitioning Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -1481,12 +1481,14 @@ impl<'v> RootCollector<'_, 'v> {
1481
1481
// Const items only generate mono items if they are actually used somewhere.
1482
1482
// Just declaring them is insufficient.
1483
1483
1484
- // But even just declaring them must collect the items they refer to
1485
- // unless their generics require monomorphization.
1486
- if !self . tcx . generics_of ( id. owner_id ) . own_requires_monomorphization ( )
1487
- && let Ok ( val) = self . tcx . const_eval_poly ( id. owner_id . to_def_id ( ) )
1488
- {
1489
- collect_const_value ( self . tcx , val, self . output ) ;
1484
+ // If we're collecting items eagerly, then recurse into all constants.
1485
+ // Otherwise the value is only collected when explicitly mentioned in other items.
1486
+ if self . strategy == MonoItemCollectionStrategy :: Eager {
1487
+ if !self . tcx . generics_of ( id. owner_id ) . own_requires_monomorphization ( )
1488
+ && let Ok ( val) = self . tcx . const_eval_poly ( id. owner_id . to_def_id ( ) )
1489
+ {
1490
+ collect_const_value ( self . tcx , val, self . output ) ;
1491
+ }
1490
1492
}
1491
1493
}
1492
1494
DefKind :: Impl { .. } => {
Original file line number Diff line number Diff line change @@ -35,7 +35,6 @@ mod mod1 {
35
35
}
36
36
}
37
37
38
- //~ MONO_ITEM fn mod1::id::<i64> @@ vtable_through_const-mod1.volatile[Internal]
39
38
fn id < T > ( x : T ) -> T {
40
39
x
41
40
}
@@ -50,8 +49,6 @@ mod mod1 {
50
49
fn do_something_else ( & self ) { }
51
50
}
52
51
53
- //~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait2>::do_something @@ vtable_through_const-mod1.volatile[External]
54
- //~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait2>::do_something_else @@ vtable_through_const-mod1.volatile[External]
55
52
impl Trait2 for NeedsDrop { }
56
53
57
54
pub trait Trait2Gen < T > {
@@ -93,8 +90,6 @@ pub fn main() {
93
90
// Same as above
94
91
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait1Gen<u8>>::do_something @@ vtable_through_const-mod1.volatile[External]
95
92
//~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait1Gen<u8>>::do_something_else @@ vtable_through_const-mod1.volatile[External]
96
- //~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait2Gen<u8>>::do_something @@ vtable_through_const-mod1.volatile[External]
97
- //~ MONO_ITEM fn <mod1::NeedsDrop as mod1::Trait2Gen<u8>>::do_something_else @@ vtable_through_const-mod1.volatile[External]
98
93
mod1:: TRAIT1_GEN_REF . do_something ( 0u8 ) ;
99
94
100
95
//~ MONO_ITEM fn mod1::id::<char> @@ vtable_through_const-mod1.volatile[External]
You can’t perform that action at this time.
0 commit comments