Skip to content

Commit 3fea201

Browse files
Rollup merge of #78061 - wesleywiser:opt_zst_const_interning, r=oli-obk
Optimize const value interning for ZST types Interning can skip any inhabited ZST type in general. Fixes #68010 r? @oli-obk
2 parents 2c1de08 + 1d07d69 commit 3fea201

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

compiler/rustc_mir/src/interpret/intern.rs

+6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir
187187
return walked;
188188
}
189189
}
190+
191+
// ZSTs do not need validation unless they're uninhabited
192+
if mplace.layout.is_zst() && !mplace.layout.abi.is_uninhabited() {
193+
return Ok(());
194+
}
195+
190196
self.walk_aggregate(mplace, fields)
191197
}
192198

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// build-pass
2+
3+
fn main() {
4+
println!("{}", [(); std::usize::MAX].len());
5+
}

0 commit comments

Comments
 (0)