Skip to content

Commit ddcdc0e

Browse files
committed
Try to shrink Alignment-related MIR in Layout
1 parent 68d2e8a commit ddcdc0e

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)