Skip to content

AlignmentEnum should just be repr(usize) now #144667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions library/core/src/ptr/alignment.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::enum_clike_unportable_variant)]

use crate::num::NonZero;
use crate::ub_checks::assert_unsafe_precondition;
use crate::{cmp, fmt, hash, mem, num};
Expand Down Expand Up @@ -241,7 +243,7 @@ impl const Default for Alignment {

#[cfg(target_pointer_width = "16")]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(u16)]
#[repr(usize)]
enum AlignmentEnum {
_Align1Shl0 = 1 << 0,
_Align1Shl1 = 1 << 1,
Expand All @@ -263,7 +265,7 @@ enum AlignmentEnum {

#[cfg(target_pointer_width = "32")]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(u32)]
#[repr(usize)]
enum AlignmentEnum {
_Align1Shl0 = 1 << 0,
_Align1Shl1 = 1 << 1,
Expand Down Expand Up @@ -301,7 +303,7 @@ enum AlignmentEnum {

#[cfg(target_pointer_width = "64")]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(u64)]
#[repr(usize)]
enum AlignmentEnum {
_Align1Shl0 = 1 << 0,
_Align1Shl1 = 1 << 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
let _2: std::ptr::NonNull<[T]>;
let mut _3: *mut [T];
let mut _4: *const [T];
let _12: ();
let _11: ();
scope 3 {
let _8: std::ptr::alignment::AlignmentEnum;
scope 4 {
Expand All @@ -31,12 +31,11 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
scope 20 (inlined NonNull::<u8>::as_ptr) {
}
scope 21 (inlined std::alloc::dealloc) {
let mut _11: usize;
let mut _10: usize;
scope 22 (inlined Layout::size) {
}
scope 23 (inlined Layout::align) {
scope 24 (inlined std::ptr::Alignment::as_usize) {
let mut _10: u32;
}
}
}
Expand Down Expand Up @@ -87,16 +86,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
bb2: {
StorageLive(_9);
_9 = copy _3 as *mut u8 (PtrToPtr);
StorageLive(_11);
StorageLive(_10);
_10 = discriminant(_8);
_11 = move _10 as usize (IntToInt);
StorageDead(_10);
_12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb3, unwind unreachable];
_11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable];
}

bb3: {
StorageDead(_11);
StorageDead(_10);
StorageDead(_9);
goto -> bb4;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
let _2: std::ptr::NonNull<[T]>;
let mut _3: *mut [T];
let mut _4: *const [T];
let _12: ();
let _11: ();
scope 3 {
let _8: std::ptr::alignment::AlignmentEnum;
scope 4 {
Expand All @@ -31,12 +31,11 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
scope 20 (inlined NonNull::<u8>::as_ptr) {
}
scope 21 (inlined std::alloc::dealloc) {
let mut _11: usize;
let mut _10: usize;
scope 22 (inlined Layout::size) {
}
scope 23 (inlined Layout::align) {
scope 24 (inlined std::ptr::Alignment::as_usize) {
let mut _10: u32;
}
}
}
Expand Down Expand Up @@ -87,16 +86,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
bb2: {
StorageLive(_9);
_9 = copy _3 as *mut u8 (PtrToPtr);
StorageLive(_11);
StorageLive(_10);
_10 = discriminant(_8);
_11 = move _10 as usize (IntToInt);
StorageDead(_10);
_12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb3, unwind unreachable];
_11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable];
}

bb3: {
StorageDead(_11);
StorageDead(_10);
StorageDead(_9);
goto -> bb4;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
let _2: std::ptr::NonNull<[T]>;
let mut _3: *mut [T];
let mut _4: *const [T];
let _12: ();
let _11: ();
scope 3 {
let _8: std::ptr::alignment::AlignmentEnum;
scope 4 {
Expand All @@ -31,12 +31,11 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
scope 20 (inlined NonNull::<u8>::as_ptr) {
}
scope 21 (inlined std::alloc::dealloc) {
let mut _11: usize;
let mut _10: usize;
scope 22 (inlined Layout::size) {
}
scope 23 (inlined Layout::align) {
scope 24 (inlined std::ptr::Alignment::as_usize) {
let mut _10: u64;
}
}
}
Expand Down Expand Up @@ -87,16 +86,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
bb2: {
StorageLive(_9);
_9 = copy _3 as *mut u8 (PtrToPtr);
StorageLive(_11);
StorageLive(_10);
_10 = discriminant(_8);
_11 = move _10 as usize (IntToInt);
StorageDead(_10);
_12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb3, unwind unreachable];
_11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable];
}

bb3: {
StorageDead(_11);
StorageDead(_10);
StorageDead(_9);
goto -> bb4;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
let _2: std::ptr::NonNull<[T]>;
let mut _3: *mut [T];
let mut _4: *const [T];
let _12: ();
let _11: ();
scope 3 {
let _8: std::ptr::alignment::AlignmentEnum;
scope 4 {
Expand All @@ -31,12 +31,11 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
scope 20 (inlined NonNull::<u8>::as_ptr) {
}
scope 21 (inlined std::alloc::dealloc) {
let mut _11: usize;
let mut _10: usize;
scope 22 (inlined Layout::size) {
}
scope 23 (inlined Layout::align) {
scope 24 (inlined std::ptr::Alignment::as_usize) {
let mut _10: u64;
}
}
}
Expand Down Expand Up @@ -87,16 +86,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
bb2: {
StorageLive(_9);
_9 = copy _3 as *mut u8 (PtrToPtr);
StorageLive(_11);
StorageLive(_10);
_10 = discriminant(_8);
_11 = move _10 as usize (IntToInt);
StorageDead(_10);
_12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb3, unwind unreachable];
_11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable];
Comment on lines 90 to +91
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way the discriminant just gives usize, rather than u64, so the no-op cast (and extra local) isn't needed any more.

}

bb3: {
StorageDead(_11);
StorageDead(_10);
StorageDead(_9);
goto -> bb4;
}
Expand Down
3 changes: 1 addition & 2 deletions tests/mir-opt/pre-codegen/drop_boxed_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub unsafe fn generic_in_place<T: Copy>(ptr: *mut Box<[T]>) {
// CHECK: [[B:_.+]] = copy [[ALIGN]] as std::ptr::Alignment (Transmute);
// CHECK: [[C:_.+]] = move ([[B]].0: std::ptr::alignment::AlignmentEnum);
// CHECK: [[D:_.+]] = discriminant([[C]]);
// CHECK: [[E:_.+]] = move [[D]] as usize (IntToInt);
// CHECK: = alloc::alloc::__rust_dealloc({{.+}}, move [[SIZE]], move [[E]]) ->
// CHECK: = alloc::alloc::__rust_dealloc({{.+}}, move [[SIZE]], move [[D]]) ->
std::ptr::drop_in_place(ptr)
}
Loading