Skip to content

Commit f6b4e45

Browse files
authored
Rollup merge of rust-lang#144667 - scottmcm:alignment-is-usize, r=tgross35
`AlignmentEnum` should just be `repr(usize)` now These used to use specific sizes because they were compiled on all widths. But now that the types themselves are `#[cfg]`'d, we can save some conversions by having it always be `repr(usize)`.
2 parents 70587eb + 4220587 commit f6b4e45

6 files changed

+22
-37
lines changed

library/core/src/ptr/alignment.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::enum_clike_unportable_variant)]
2+
13
use crate::num::NonZero;
24
use crate::ub_checks::assert_unsafe_precondition;
35
use crate::{cmp, fmt, hash, mem, num};
@@ -241,7 +243,7 @@ impl const Default for Alignment {
241243

242244
#[cfg(target_pointer_width = "16")]
243245
#[derive(Copy, Clone, PartialEq, Eq)]
244-
#[repr(u16)]
246+
#[repr(usize)]
245247
enum AlignmentEnum {
246248
_Align1Shl0 = 1 << 0,
247249
_Align1Shl1 = 1 << 1,
@@ -263,7 +265,7 @@ enum AlignmentEnum {
263265

264266
#[cfg(target_pointer_width = "32")]
265267
#[derive(Copy, Clone, PartialEq, Eq)]
266-
#[repr(u32)]
268+
#[repr(usize)]
267269
enum AlignmentEnum {
268270
_Align1Shl0 = 1 << 0,
269271
_Align1Shl1 = 1 << 1,
@@ -301,7 +303,7 @@ enum AlignmentEnum {
301303

302304
#[cfg(target_pointer_width = "64")]
303305
#[derive(Copy, Clone, PartialEq, Eq)]
304-
#[repr(u64)]
306+
#[repr(usize)]
305307
enum AlignmentEnum {
306308
_Align1Shl0 = 1 << 0,
307309
_Align1Shl1 = 1 << 1,

tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
88
let _2: std::ptr::NonNull<[T]>;
99
let mut _3: *mut [T];
1010
let mut _4: *const [T];
11-
let _12: ();
11+
let _11: ();
1212
scope 3 {
1313
let _8: std::ptr::alignment::AlignmentEnum;
1414
scope 4 {
@@ -31,12 +31,11 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
3131
scope 20 (inlined NonNull::<u8>::as_ptr) {
3232
}
3333
scope 21 (inlined std::alloc::dealloc) {
34-
let mut _11: usize;
34+
let mut _10: usize;
3535
scope 22 (inlined Layout::size) {
3636
}
3737
scope 23 (inlined Layout::align) {
3838
scope 24 (inlined std::ptr::Alignment::as_usize) {
39-
let mut _10: u32;
4039
}
4140
}
4241
}
@@ -87,16 +86,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
8786
bb2: {
8887
StorageLive(_9);
8988
_9 = copy _3 as *mut u8 (PtrToPtr);
90-
StorageLive(_11);
9189
StorageLive(_10);
9290
_10 = discriminant(_8);
93-
_11 = move _10 as usize (IntToInt);
94-
StorageDead(_10);
95-
_12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb3, unwind unreachable];
91+
_11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable];
9692
}
9793

9894
bb3: {
99-
StorageDead(_11);
95+
StorageDead(_10);
10096
StorageDead(_9);
10197
goto -> bb4;
10298
}

tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
88
let _2: std::ptr::NonNull<[T]>;
99
let mut _3: *mut [T];
1010
let mut _4: *const [T];
11-
let _12: ();
11+
let _11: ();
1212
scope 3 {
1313
let _8: std::ptr::alignment::AlignmentEnum;
1414
scope 4 {
@@ -31,12 +31,11 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
3131
scope 20 (inlined NonNull::<u8>::as_ptr) {
3232
}
3333
scope 21 (inlined std::alloc::dealloc) {
34-
let mut _11: usize;
34+
let mut _10: usize;
3535
scope 22 (inlined Layout::size) {
3636
}
3737
scope 23 (inlined Layout::align) {
3838
scope 24 (inlined std::ptr::Alignment::as_usize) {
39-
let mut _10: u32;
4039
}
4140
}
4241
}
@@ -87,16 +86,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
8786
bb2: {
8887
StorageLive(_9);
8988
_9 = copy _3 as *mut u8 (PtrToPtr);
90-
StorageLive(_11);
9189
StorageLive(_10);
9290
_10 = discriminant(_8);
93-
_11 = move _10 as usize (IntToInt);
94-
StorageDead(_10);
95-
_12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb3, unwind unreachable];
91+
_11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable];
9692
}
9793

9894
bb3: {
99-
StorageDead(_11);
95+
StorageDead(_10);
10096
StorageDead(_9);
10197
goto -> bb4;
10298
}

tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
88
let _2: std::ptr::NonNull<[T]>;
99
let mut _3: *mut [T];
1010
let mut _4: *const [T];
11-
let _12: ();
11+
let _11: ();
1212
scope 3 {
1313
let _8: std::ptr::alignment::AlignmentEnum;
1414
scope 4 {
@@ -31,12 +31,11 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
3131
scope 20 (inlined NonNull::<u8>::as_ptr) {
3232
}
3333
scope 21 (inlined std::alloc::dealloc) {
34-
let mut _11: usize;
34+
let mut _10: usize;
3535
scope 22 (inlined Layout::size) {
3636
}
3737
scope 23 (inlined Layout::align) {
3838
scope 24 (inlined std::ptr::Alignment::as_usize) {
39-
let mut _10: u64;
4039
}
4140
}
4241
}
@@ -87,16 +86,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
8786
bb2: {
8887
StorageLive(_9);
8988
_9 = copy _3 as *mut u8 (PtrToPtr);
90-
StorageLive(_11);
9189
StorageLive(_10);
9290
_10 = discriminant(_8);
93-
_11 = move _10 as usize (IntToInt);
94-
StorageDead(_10);
95-
_12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb3, unwind unreachable];
91+
_11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable];
9692
}
9793

9894
bb3: {
99-
StorageDead(_11);
95+
StorageDead(_10);
10096
StorageDead(_9);
10197
goto -> bb4;
10298
}

tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
88
let _2: std::ptr::NonNull<[T]>;
99
let mut _3: *mut [T];
1010
let mut _4: *const [T];
11-
let _12: ();
11+
let _11: ();
1212
scope 3 {
1313
let _8: std::ptr::alignment::AlignmentEnum;
1414
scope 4 {
@@ -31,12 +31,11 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
3131
scope 20 (inlined NonNull::<u8>::as_ptr) {
3232
}
3333
scope 21 (inlined std::alloc::dealloc) {
34-
let mut _11: usize;
34+
let mut _10: usize;
3535
scope 22 (inlined Layout::size) {
3636
}
3737
scope 23 (inlined Layout::align) {
3838
scope 24 (inlined std::ptr::Alignment::as_usize) {
39-
let mut _10: u64;
4039
}
4140
}
4241
}
@@ -87,16 +86,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
8786
bb2: {
8887
StorageLive(_9);
8988
_9 = copy _3 as *mut u8 (PtrToPtr);
90-
StorageLive(_11);
9189
StorageLive(_10);
9290
_10 = discriminant(_8);
93-
_11 = move _10 as usize (IntToInt);
94-
StorageDead(_10);
95-
_12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb3, unwind unreachable];
91+
_11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable];
9692
}
9793

9894
bb3: {
99-
StorageDead(_11);
95+
StorageDead(_10);
10096
StorageDead(_9);
10197
goto -> bb4;
10298
}

tests/mir-opt/pre-codegen/drop_boxed_slice.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub unsafe fn generic_in_place<T: Copy>(ptr: *mut Box<[T]>) {
1313
// CHECK: [[B:_.+]] = copy [[ALIGN]] as std::ptr::Alignment (Transmute);
1414
// CHECK: [[C:_.+]] = move ([[B]].0: std::ptr::alignment::AlignmentEnum);
1515
// CHECK: [[D:_.+]] = discriminant([[C]]);
16-
// CHECK: [[E:_.+]] = move [[D]] as usize (IntToInt);
17-
// CHECK: = alloc::alloc::__rust_dealloc({{.+}}, move [[SIZE]], move [[E]]) ->
16+
// CHECK: = alloc::alloc::__rust_dealloc({{.+}}, move [[SIZE]], move [[D]]) ->
1817
std::ptr::drop_in_place(ptr)
1918
}

0 commit comments

Comments
 (0)