Skip to content

Commit 688a0c0

Browse files
committed
Auto merge of rust-lang#128918 - scottmcm:tweak-alignment-mir, r=<try>
Try to shrink `Alignment`-related MIR in `Layout` Noticed all this in <https://rust.godbolt.org/z/55Tx65v4e>: ```rust _22 = (_11.0: std::ptr::alignment::AlignmentEnum); _23 = discriminant(_22); _24 = Ge(_23, const 1_u64); _25 = Le(_23, const 9223372036854775808_u64); _26 = BitAnd(move _24, move _25); assume(move _26); _20 = _23 as usize (IntToInt); ``` So let's see if a non-`as` here works better.
2 parents 19469cb + ddcdc0e commit 688a0c0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

library/core/src/ptr/alignment.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ impl Alignment {
9494
#[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
9595
#[inline]
9696
pub const fn as_usize(self) -> usize {
97-
self.0 as usize
97+
// It would be possible to do this with `self.0 as _`, but that results
98+
// in way more MIR -- mostly because of the assume -- which ends up
99+
// impacting compilation time for things using `Layout`.
100+
101+
// SAFETY: this type is a subset of the possible values of usize.
102+
unsafe { mem::transmute::<Alignment, usize>(self) }
98103
}
99104

100105
/// Returns the alignment as a <code>[NonZero]<[usize]></code>.

0 commit comments

Comments
 (0)