Skip to content

Commit a913065

Browse files
committed
fix rustfmt and bless tidy/tests
1 parent cf61cbc commit a913065

6 files changed

Lines changed: 80 additions & 95 deletions

library/alloc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@
108108
#![feature(const_destruct)]
109109
#![feature(const_eval_select)]
110110
#![feature(const_heap)]
111-
#![feature(copied_into_inner)]
112111
#![feature(const_option_ops)]
113112
#![feature(const_try)]
113+
#![feature(copied_into_inner)]
114114
#![feature(core_intrinsics)]
115115
#![feature(deprecated_suggestion)]
116116
#![feature(deref_pure_trait)]

library/alloc/src/raw_vec/mod.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ const fn min_non_zero_cap(size: usize) -> usize {
165165
}
166166
}
167167

168+
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
169+
#[rustfmt::skip] // FIXME(fee1-dead): temporary measure before rustfmt is bumped
168170
const impl<T, A: [const] Allocator + [const] Destruct> RawVec<T, A> {
169171
/// Like `with_capacity`, but parameterized over the choice of
170172
/// allocator for the returned `RawVec`.
171173
#[cfg(not(no_global_oom_handling))]
172174
#[inline]
173-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
174-
pub(crate) fn with_capacity_in(capacity: usize, alloc: A) -> Self
175-
{
175+
pub(crate) fn with_capacity_in(capacity: usize, alloc: A) -> Self {
176176
Self {
177177
inner: RawVecInner::with_capacity_in(capacity, alloc, T::LAYOUT),
178178
_marker: PhantomData,
@@ -183,9 +183,7 @@ const impl<T, A: [const] Allocator + [const] Destruct> RawVec<T, A> {
183183
/// caller to ensure `len == self.capacity()`.
184184
#[cfg(not(no_global_oom_handling))]
185185
#[inline(never)]
186-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
187-
pub(crate) fn grow_one(&mut self)
188-
{
186+
pub(crate) fn grow_one(&mut self) {
189187
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
190188
unsafe { self.inner.grow_one(T::LAYOUT) }
191189
}
@@ -411,12 +409,12 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec<T, A> {
411409
}
412410
}
413411

412+
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
413+
#[rustfmt::skip] // FIXME(fee1-dead): temporary measure before rustfmt is bumped
414414
const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
415415
#[cfg(not(no_global_oom_handling))]
416416
#[inline]
417-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
418-
fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self
419-
{
417+
fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self {
420418
match Self::try_allocate_in(capacity, AllocInit::Uninitialized, alloc, elem_layout) {
421419
Ok(this) => {
422420
unsafe {
@@ -428,14 +426,13 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
428426
Err(err) => handle_error(err),
429427
}
430428
}
431-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
429+
432430
fn try_allocate_in(
433431
capacity: usize,
434432
init: AllocInit,
435433
alloc: A,
436434
elem_layout: Layout,
437-
) -> Result<Self, TryReserveError>
438-
{
435+
) -> Result<Self, TryReserveError> {
439436
// We avoid `unwrap_or_else` here because it bloats the amount of
440437
// LLVM IR generated.
441438
let layout = match layout_array(capacity, elem_layout) {
@@ -474,29 +471,24 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
474471
/// - `elem_layout`'s size must be a multiple of its alignment
475472
#[cfg(not(no_global_oom_handling))]
476473
#[inline]
477-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
478-
unsafe fn grow_one(&mut self, elem_layout: Layout)
479-
{
474+
unsafe fn grow_one(&mut self, elem_layout: Layout) {
480475
// SAFETY: Precondition passed to caller
481476
if let Err(err) = unsafe { self.grow_amortized(self.cap.as_inner(), 1, elem_layout) } {
482477
handle_error(err);
483478
}
484479
}
485480

486-
487481
/// # Safety
488482
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
489483
/// initially construct `self`
490484
/// - `elem_layout`'s size must be a multiple of its alignment
491485
/// - The sum of `len` and `additional` must be greater than the current capacity
492-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
493486
unsafe fn grow_amortized(
494487
&mut self,
495488
len: usize,
496489
additional: usize,
497490
elem_layout: Layout,
498-
) -> Result<(), TryReserveError>
499-
{
491+
) -> Result<(), TryReserveError> {
500492
// This is ensured by the calling contexts.
501493
debug_assert!(additional > 0);
502494

@@ -532,13 +524,11 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
532524
// not marked inline(never) since we want optimizers to be able to observe the specifics of this
533525
// function, see tests/codegen-llvm/vec-reserve-extend.rs.
534526
#[cold]
535-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
536527
unsafe fn finish_grow(
537528
&self,
538529
cap: usize,
539530
elem_layout: Layout,
540-
) -> Result<NonNull<[u8]>, TryReserveError>
541-
{
531+
) -> Result<NonNull<[u8]>, TryReserveError> {
542532
let new_layout = layout_array(cap, elem_layout)?;
543533

544534
let memory = if let Some((ptr, old_layout)) = unsafe { self.current_memory(elem_layout) } {

library/alloc/src/vec/mod.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,9 @@ impl<T> Vec<T> {
902902
}
903903
}
904904

905+
#[cfg(not(no_global_oom_handling))]
906+
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
907+
#[rustfmt::skip] // FIXME(fee1-dead): temporary measure before rustfmt is bumped
905908
const impl<T, A: [const] Allocator + [const] Destruct> Vec<T, A> {
906909
/// Constructs a new, empty `Vec<T, A>` with at least the specified capacity
907910
/// with the provided allocator.
@@ -958,16 +961,12 @@ const impl<T, A: [const] Allocator + [const] Destruct> Vec<T, A> {
958961
/// let vec_units = Vec::<(), System>::with_capacity_in(10, System);
959962
/// assert_eq!(vec_units.capacity(), usize::MAX);
960963
/// ```
961-
#[cfg(not(no_global_oom_handling))]
962964
#[inline]
963965
#[unstable(feature = "allocator_api", issue = "32838")]
964-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
965-
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self
966-
{
966+
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
967967
Vec { buf: RawVec::with_capacity_in(capacity, alloc), len: 0 }
968968
}
969969

970-
971970
/// Appends an element to the back of a collection.
972971
///
973972
/// # Panics
@@ -988,13 +987,10 @@ const impl<T, A: [const] Allocator + [const] Destruct> Vec<T, A> {
988987
/// capacity after the push, *O*(*capacity*) time is taken to copy the
989988
/// vector's elements to a larger allocation. This expensive operation is
990989
/// offset by the *capacity* *O*(1) insertions it allows.
991-
#[cfg(not(no_global_oom_handling))]
992990
#[inline]
993991
#[stable(feature = "rust1", since = "1.0.0")]
994992
#[rustc_confusables("push_back", "put", "append")]
995-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
996-
pub fn push(&mut self, value: T)
997-
{
993+
pub fn push(&mut self, value: T) {
998994
let _ = self.push_mut(value);
999995
}
1000996

@@ -1026,13 +1022,10 @@ const impl<T, A: [const] Allocator + [const] Destruct> Vec<T, A> {
10261022
/// capacity after the push, *O*(*capacity*) time is taken to copy the
10271023
/// vector's elements to a larger allocation. This expensive operation is
10281024
/// offset by the *capacity* *O*(1) insertions it allows.
1029-
#[cfg(not(no_global_oom_handling))]
10301025
#[inline]
10311026
#[unstable(feature = "push_mut", issue = "135974")]
10321027
#[must_use = "if you don't need a reference to the value, use `Vec::push` instead"]
1033-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
1034-
pub fn push_mut(&mut self, value: T) -> &mut T
1035-
{
1028+
pub fn push_mut(&mut self, value: T) -> &mut T {
10361029
// Inform codegen that the length does not change across grow_one().
10371030
let len = self.len;
10381031
// This will panic or abort if we would allocate > isize::MAX bytes

tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
scope 4 {
2727
debug _x => _8;
2828
}
29-
scope 18 (inlined foo) {
29+
scope 19 (inlined foo) {
3030
let mut _27: *const [()];
3131
}
3232
}
33-
scope 16 (inlined slice_from_raw_parts::<()>) {
34-
scope 17 (inlined std::ptr::from_raw_parts::<[()], ()>) {
33+
scope 17 (inlined slice_from_raw_parts::<()>) {
34+
scope 18 (inlined std::ptr::from_raw_parts::<[()], ()>) {
3535
}
3636
}
3737
}
@@ -49,19 +49,21 @@
4949
scope 7 {
5050
let _21: std::ptr::NonNull<[u8]>;
5151
scope 8 {
52-
scope 11 (inlined NonNull::<[u8]>::as_mut_ptr) {
53-
scope 12 (inlined NonNull::<[u8]>::as_non_null_ptr) {
54-
scope 13 (inlined NonNull::<[u8]>::cast::<u8>) {
52+
scope 12 (inlined NonNull::<[u8]>::as_mut_ptr) {
53+
scope 13 (inlined NonNull::<[u8]>::as_non_null_ptr) {
54+
scope 14 (inlined NonNull::<[u8]>::cast::<u8>) {
5555
let mut _25: *mut [u8];
56-
scope 14 (inlined NonNull::<[u8]>::as_ptr) {
56+
scope 15 (inlined NonNull::<[u8]>::as_ptr) {
5757
}
5858
}
5959
}
60-
scope 15 (inlined NonNull::<u8>::as_ptr) {
60+
scope 16 (inlined NonNull::<u8>::as_ptr) {
6161
}
6262
}
6363
}
6464
scope 10 (inlined <std::alloc::Global as Allocator>::allocate) {
65+
scope 11 (inlined std::alloc::Global::alloc_impl) {
66+
}
6567
}
6668
}
6769
scope 9 (inlined #[track_caller] Layout::from_size_align_unchecked) {
@@ -192,8 +194,8 @@
192194
+ _18 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }};
193195
StorageDead(_24);
194196
StorageLive(_19);
195-
- _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], copy _18, const false) -> [return: bb7, unwind unreachable];
196-
+ _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}, const false) -> [return: bb7, unwind unreachable];
197+
- _19 = std::alloc::Global::alloc_impl_runtime(copy _18, const false) -> [return: bb7, unwind unreachable];
198+
+ _19 = std::alloc::Global::alloc_impl_runtime(const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}, const false) -> [return: bb7, unwind unreachable];
197199
}
198200

199201
bb7: {

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
2525
}
2626
}
2727
scope 18 (inlined <std::alloc::Global as Allocator>::deallocate) {
28-
let mut _9: *mut u8;
29-
scope 19 (inlined Layout::size) {
30-
}
31-
scope 20 (inlined NonNull::<u8>::as_ptr) {
32-
}
33-
scope 21 (inlined std::alloc::dealloc) {
34-
let mut _10: usize;
35-
scope 22 (inlined Layout::size) {
36-
}
37-
scope 23 (inlined Layout::align) {
38-
scope 24 (inlined std::ptr::Alignment::as_usize) {
28+
scope 19 (inlined std::alloc::Global::deallocate_impl) {
29+
scope 20 (inlined std::alloc::Global::deallocate_impl_runtime) {
30+
let mut _9: *mut u8;
31+
scope 21 (inlined Layout::size) {
32+
}
33+
scope 22 (inlined NonNull::<u8>::as_ptr) {
34+
}
35+
scope 23 (inlined std::alloc::dealloc) {
36+
let mut _10: usize;
37+
scope 24 (inlined Layout::size) {
38+
}
39+
scope 25 (inlined Layout::align) {
40+
scope 26 (inlined std::ptr::Alignment::as_usize) {
41+
}
42+
}
3943
}
4044
}
4145
}

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@
99
let mut _4: *mut [u8];
1010
let mut _5: std::ptr::NonNull<[u8]>;
1111
let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
12-
let mut _7: &std::alloc::Global;
13-
let mut _8: std::alloc::Layout;
12+
let mut _7: std::alloc::Layout;
1413
scope 1 {
1514
debug layout => _1;
16-
let mut _9: &std::alloc::Global;
1715
scope 2 {
1816
debug ptr => _3;
1917
}
2018
scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
21-
}
22-
scope 6 (inlined #[track_caller] Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap) {
23-
let mut _12: isize;
24-
let _13: std::alloc::AllocError;
25-
let mut _14: !;
26-
let mut _15: &dyn std::fmt::Debug;
27-
let _16: &std::alloc::AllocError;
28-
scope 7 {
19+
scope 6 (inlined std::alloc::Global::alloc_impl) {
2920
}
21+
}
22+
scope 7 (inlined #[track_caller] Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap) {
23+
let mut _10: isize;
24+
let _11: std::alloc::AllocError;
25+
let mut _12: !;
26+
let mut _13: &dyn std::fmt::Debug;
27+
let _14: &std::alloc::AllocError;
3028
scope 8 {
3129
}
30+
scope 9 {
31+
}
3232
}
33-
scope 9 (inlined NonNull::<[u8]>::as_ptr) {
33+
scope 10 (inlined NonNull::<[u8]>::as_ptr) {
3434
}
3535
}
3636
scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
37-
let mut _10: isize;
38-
let mut _11: !;
37+
let mut _8: isize;
38+
let mut _9: !;
3939
scope 4 {
4040
}
4141
}
@@ -46,10 +46,10 @@
4646
StorageLive(_2);
4747
- _2 = Option::<Layout>::None;
4848
+ _2 = const Option::<Layout>::None;
49-
StorageLive(_10);
50-
- _10 = discriminant(_2);
51-
- switchInt(move _10) -> [0: bb2, 1: bb3, otherwise: bb1];
52-
+ _10 = const 0_isize;
49+
StorageLive(_8);
50+
- _8 = discriminant(_2);
51+
- switchInt(move _8) -> [0: bb2, 1: bb3, otherwise: bb1];
52+
+ _8 = const 0_isize;
5353
+ switchInt(const 0_isize) -> [0: bb2, 1: bb3, otherwise: bb1];
5454
}
5555

@@ -58,48 +58,44 @@
5858
}
5959

6060
bb2: {
61-
_11 = option::unwrap_failed() -> unwind unreachable;
61+
_9 = option::unwrap_failed() -> unwind unreachable;
6262
}
6363

6464
bb3: {
6565
- _1 = move ((_2 as Some).0: std::alloc::Layout);
6666
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
67-
StorageDead(_10);
67+
StorageDead(_8);
6868
StorageDead(_2);
6969
StorageLive(_3);
7070
StorageLive(_4);
7171
StorageLive(_5);
7272
StorageLive(_6);
7373
StorageLive(_7);
74-
_9 = const main::promoted[0];
75-
_7 = copy _9;
76-
StorageLive(_8);
77-
- _8 = copy _1;
78-
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb4, unwind unreachable];
79-
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
80-
+ _6 = std::alloc::Global::alloc_impl(copy _9, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb4, unwind unreachable];
74+
- _7 = copy _1;
75+
- _6 = std::alloc::Global::alloc_impl_runtime(move _7, const false) -> [return: bb4, unwind unreachable];
76+
+ _7 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
77+
+ _6 = std::alloc::Global::alloc_impl_runtime(const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb4, unwind unreachable];
8178
}
8279

8380
bb4: {
84-
StorageDead(_8);
8581
StorageDead(_7);
86-
StorageLive(_12);
87-
StorageLive(_16);
88-
_12 = discriminant(_6);
89-
switchInt(move _12) -> [0: bb6, 1: bb5, otherwise: bb1];
82+
StorageLive(_10);
83+
StorageLive(_14);
84+
_10 = discriminant(_6);
85+
switchInt(move _10) -> [0: bb6, 1: bb5, otherwise: bb1];
9086
}
9187

9288
bb5: {
93-
StorageLive(_15);
94-
_16 = &_13;
95-
_15 = copy _16 as &dyn std::fmt::Debug (PointerCoercion(Unsize, Implicit));
96-
_14 = result::unwrap_failed(const "called `Result::unwrap()` on an `Err` value", move _15) -> unwind unreachable;
89+
StorageLive(_13);
90+
_14 = &_11;
91+
_13 = copy _14 as &dyn std::fmt::Debug (PointerCoercion(Unsize, Implicit));
92+
_12 = result::unwrap_failed(const "called `Result::unwrap()` on an `Err` value", move _13) -> unwind unreachable;
9793
}
9894

9995
bb6: {
10096
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
101-
StorageDead(_16);
102-
StorageDead(_12);
97+
StorageDead(_14);
98+
StorageDead(_10);
10399
StorageDead(_6);
104100
_4 = copy _5 as *mut [u8] (Transmute);
105101
StorageDead(_5);

0 commit comments

Comments
 (0)