Skip to content

Commit f30a0ad

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 4afc77f + f396849 commit f30a0ad

29 files changed

+105
-82
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

alloc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010

1111
[dependencies]
1212
core = { path = "../core" }
13-
compiler_builtins = { version = "0.1.123", features = ['rustc-dep-of-std'] }
13+
compiler_builtins = { version = "0.1.125", features = ['rustc-dep-of-std'] }
1414

1515
[dev-dependencies]
1616
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

alloc/src/alloc.rs

+13
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub use std::alloc::Global;
8989
#[stable(feature = "global_alloc", since = "1.28.0")]
9090
#[must_use = "losing the pointer will leak memory"]
9191
#[inline]
92+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
9293
pub unsafe fn alloc(layout: Layout) -> *mut u8 {
9394
unsafe {
9495
// Make sure we don't accidentally allow omitting the allocator shim in
@@ -113,6 +114,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
113114
/// See [`GlobalAlloc::dealloc`].
114115
#[stable(feature = "global_alloc", since = "1.28.0")]
115116
#[inline]
117+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
116118
pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
117119
unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
118120
}
@@ -132,6 +134,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
132134
#[stable(feature = "global_alloc", since = "1.28.0")]
133135
#[must_use = "losing the pointer will leak memory"]
134136
#[inline]
137+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
135138
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
136139
unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
137140
}
@@ -166,13 +169,15 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
166169
#[stable(feature = "global_alloc", since = "1.28.0")]
167170
#[must_use = "losing the pointer will leak memory"]
168171
#[inline]
172+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
169173
pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
170174
unsafe { __rust_alloc_zeroed(layout.size(), layout.align()) }
171175
}
172176

173177
#[cfg(not(test))]
174178
impl Global {
175179
#[inline]
180+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
176181
fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocError> {
177182
match layout.size() {
178183
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
@@ -187,6 +192,7 @@ impl Global {
187192

188193
// SAFETY: Same as `Allocator::grow`
189194
#[inline]
195+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
190196
unsafe fn grow_impl(
191197
&self,
192198
ptr: NonNull<u8>,
@@ -237,16 +243,19 @@ impl Global {
237243
#[cfg(not(test))]
238244
unsafe impl Allocator for Global {
239245
#[inline]
246+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
240247
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
241248
self.alloc_impl(layout, false)
242249
}
243250

244251
#[inline]
252+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
245253
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
246254
self.alloc_impl(layout, true)
247255
}
248256

249257
#[inline]
258+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
250259
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
251260
if layout.size() != 0 {
252261
// SAFETY: `layout` is non-zero in size,
@@ -256,6 +265,7 @@ unsafe impl Allocator for Global {
256265
}
257266

258267
#[inline]
268+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
259269
unsafe fn grow(
260270
&self,
261271
ptr: NonNull<u8>,
@@ -267,6 +277,7 @@ unsafe impl Allocator for Global {
267277
}
268278

269279
#[inline]
280+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
270281
unsafe fn grow_zeroed(
271282
&self,
272283
ptr: NonNull<u8>,
@@ -278,6 +289,7 @@ unsafe impl Allocator for Global {
278289
}
279290

280291
#[inline]
292+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
281293
unsafe fn shrink(
282294
&self,
283295
ptr: NonNull<u8>,
@@ -325,6 +337,7 @@ unsafe impl Allocator for Global {
325337
#[cfg(all(not(no_global_oom_handling), not(test)))]
326338
#[lang = "exchange_malloc"]
327339
#[inline]
340+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
328341
unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
329342
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
330343
match Global.allocate(layout) {

alloc/src/boxed.rs

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ impl<T> Box<T> {
250250
#[stable(feature = "rust1", since = "1.0.0")]
251251
#[must_use]
252252
#[rustc_diagnostic_item = "box_new"]
253+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
253254
pub fn new(x: T) -> Self {
254255
#[rustc_box]
255256
Box::new(x)

alloc/src/collections/vec_deque/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ impl<T> VecDeque<T> {
554554
#[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")]
555555
#[must_use]
556556
pub const fn new() -> VecDeque<T> {
557-
// FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable.
558-
VecDeque { head: 0, len: 0, buf: RawVec::NEW }
557+
// FIXME(const-hack): This should just be `VecDeque::new_in(Global)` once that hits stable.
558+
VecDeque { head: 0, len: 0, buf: RawVec::new() }
559559
}
560560

561561
/// Creates an empty deque with space for at least `capacity` elements.

alloc/src/raw_vec.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ struct RawVecInner<A: Allocator = Global> {
9696
}
9797

9898
impl<T> RawVec<T, Global> {
99-
/// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so
100-
/// they cannot call `Self::new()`.
101-
///
102-
/// If you change `RawVec<T>::new` or dependencies, please take care to not introduce anything
103-
/// that would truly const-call something unstable.
104-
pub const NEW: Self = Self::new();
105-
10699
/// Creates the biggest possible `RawVec` (on the system heap)
107100
/// without allocating. If `T` has positive size, then this makes a
108101
/// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
@@ -111,7 +104,7 @@ impl<T> RawVec<T, Global> {
111104
#[must_use]
112105
#[rustc_const_stable(feature = "raw_vec_internals_const", since = "1.81")]
113106
pub const fn new() -> Self {
114-
Self { inner: RawVecInner::new::<T>(), _marker: PhantomData }
107+
Self::new_in(Global)
115108
}
116109

117110
/// Creates a `RawVec` (on the system heap) with exactly the
@@ -149,12 +142,6 @@ impl<T> RawVec<T, Global> {
149142
}
150143

151144
impl RawVecInner<Global> {
152-
#[must_use]
153-
#[rustc_const_stable(feature = "raw_vec_internals_const", since = "1.81")]
154-
const fn new<T>() -> Self {
155-
Self::new_in(Global, core::mem::align_of::<T>())
156-
}
157-
158145
#[cfg(not(any(no_global_oom_handling, test)))]
159146
#[must_use]
160147
#[inline]

alloc/src/vec/in_place_collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const fn in_place_collectible<DEST, SRC>(
191191

192192
const fn needs_realloc<SRC, DEST>(src_cap: usize, dst_cap: usize) -> bool {
193193
if const { mem::align_of::<SRC>() != mem::align_of::<DEST>() } {
194-
// FIXME: use unreachable! once that works in const
194+
// FIXME(const-hack): use unreachable! once that works in const
195195
panic!("in_place_collectible() prevents this");
196196
}
197197

alloc/src/vec/into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<T, A: Allocator> IntoIter<T, A> {
142142
// struct and then overwriting &mut self.
143143
// this creates less assembly
144144
self.cap = 0;
145-
self.buf = RawVec::NEW.non_null();
145+
self.buf = RawVec::new().non_null();
146146
self.ptr = self.buf;
147147
self.end = self.buf.as_ptr();
148148

alloc/src/vec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl<T> Vec<T> {
419419
#[stable(feature = "rust1", since = "1.0.0")]
420420
#[must_use]
421421
pub const fn new() -> Self {
422-
Vec { buf: RawVec::NEW, len: 0 }
422+
Vec { buf: RawVec::new(), len: 0 }
423423
}
424424

425425
/// Constructs a new, empty `Vec<T>` with at least the specified capacity.

core/src/char/convert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ub_checks::assert_unsafe_precondition;
1111
#[must_use]
1212
#[inline]
1313
pub(super) const fn from_u32(i: u32) -> Option<char> {
14-
// FIXME: once Result::ok is const fn, use it here
14+
// FIXME(const-hack): once Result::ok is const fn, use it here
1515
match char_try_from_u32(i) {
1616
Ok(c) => Some(c),
1717
Err(_) => None,

core/src/char/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl char {
383383
// Force the 6th bit to be set to ensure ascii is lower case.
384384
digit = (self as u32 | 0b10_0000).wrapping_sub('a' as u32).saturating_add(10);
385385
}
386-
// FIXME: once then_some is const fn, use it here
386+
// FIXME(const-hack): once then_some is const fn, use it here
387387
if digit < radix { Some(digit) } else { None }
388388
}
389389

core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@
149149
#![feature(const_size_of_val_raw)]
150150
#![feature(const_slice_from_raw_parts_mut)]
151151
#![feature(const_slice_from_ref)]
152-
#![feature(const_slice_index)]
153152
#![feature(const_slice_split_at_mut)]
154153
#![feature(const_str_from_utf8_unchecked_mut)]
155154
#![feature(const_strict_overflow_ops)]

core/src/num/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::str::FromStr;
66
use crate::ub_checks::assert_unsafe_precondition;
77
use crate::{ascii, intrinsics, mem};
88

9-
// Used because the `?` operator is not allowed in a const context.
9+
// FIXME(const-hack): Used because the `?` operator is not allowed in a const context.
1010
macro_rules! try_opt {
1111
($e:expr) => {
1212
match $e {

core/src/option.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ impl<T> Option<T> {
739739
#[stable(feature = "pin", since = "1.33.0")]
740740
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
741741
pub const fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
742+
// FIXME(const-hack): use `map` once that is possible
742743
match Pin::get_ref(self).as_ref() {
743744
// SAFETY: `x` is guaranteed to be pinned because it comes from `self`
744745
// which is pinned.
@@ -758,6 +759,7 @@ impl<T> Option<T> {
758759
// SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.
759760
// `x` is guaranteed to be pinned because it comes from `self` which is pinned.
760761
unsafe {
762+
// FIXME(const-hack): use `map` once that is possible
761763
match Pin::get_unchecked_mut(self).as_mut() {
762764
Some(x) => Some(Pin::new_unchecked(x)),
763765
None => None,
@@ -1290,10 +1292,7 @@ impl<T> Option<T> {
12901292
where
12911293
T: Deref,
12921294
{
1293-
match self.as_ref() {
1294-
Some(t) => Some(t.deref()),
1295-
None => None,
1296-
}
1295+
self.as_ref().map(|t| t.deref())
12971296
}
12981297

12991298
/// Converts from `Option<T>` (or `&mut Option<T>`) to `Option<&mut T::Target>`.
@@ -1316,10 +1315,7 @@ impl<T> Option<T> {
13161315
where
13171316
T: DerefMut,
13181317
{
1319-
match self.as_mut() {
1320-
Some(t) => Some(t.deref_mut()),
1321-
None => None,
1322-
}
1318+
self.as_mut().map(|t| t.deref_mut())
13231319
}
13241320

13251321
/////////////////////////////////////////////////////////////////////////
@@ -1632,13 +1628,7 @@ impl<T> Option<T> {
16321628
#[inline]
16331629
#[stable(feature = "option_entry", since = "1.20.0")]
16341630
pub fn get_or_insert(&mut self, value: T) -> &mut T {
1635-
if let None = *self {
1636-
*self = Some(value);
1637-
}
1638-
1639-
// SAFETY: a `None` variant for `self` would have been replaced by a `Some`
1640-
// variant in the code above.
1641-
unsafe { self.as_mut().unwrap_unchecked() }
1631+
self.get_or_insert_with(|| value)
16421632
}
16431633

16441634
/// Inserts the default value into the option if it is [`None`], then
@@ -1724,7 +1714,7 @@ impl<T> Option<T> {
17241714
#[stable(feature = "rust1", since = "1.0.0")]
17251715
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
17261716
pub const fn take(&mut self) -> Option<T> {
1727-
// FIXME replace `mem::replace` by `mem::take` when the latter is const ready
1717+
// FIXME(const-hack) replace `mem::replace` by `mem::take` when the latter is const ready
17281718
mem::replace(self, None)
17291719
}
17301720

core/src/panic.rs

+25
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ pub macro unreachable_2021 {
140140
),
141141
}
142142

143+
/// Invokes a closure, aborting if the closure unwinds.
144+
///
145+
/// When compiled with aborting panics, this function is effectively a no-op.
146+
/// With unwinding panics, an unwind results in another call into the panic
147+
/// hook followed by a process abort.
148+
///
149+
/// # Notes
150+
///
151+
/// Instead of using this function, code should attempt to support unwinding.
152+
/// Implementing [`Drop`] allows you to restore invariants uniformly in both
153+
/// return and unwind paths.
154+
///
155+
/// If an unwind can lead to logical issues but not soundness issues, you
156+
/// should allow the unwind. Opting out of [`UnwindSafe`] indicates to your
157+
/// consumers that they need to consider correctness in the face of unwinds.
158+
///
159+
/// If an unwind would be unsound, then this function should be used in order
160+
/// to prevent unwinds. However, note that `extern "C" fn` will automatically
161+
/// convert unwinds to aborts, so using this function isn't necessary for FFI.
162+
#[unstable(feature = "abort_unwind", issue = "130338")]
163+
#[rustc_nounwind]
164+
pub fn abort_unwind<F: FnOnce() -> R, R>(f: F) -> R {
165+
f()
166+
}
167+
143168
/// An internal trait used by std to pass data from std to `panic_unwind` and
144169
/// other panic runtimes. Not intended to be stabilized any time soon, do not
145170
/// use.

core/src/ptr/alignment.rs

-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ impl From<Alignment> for usize {
199199
}
200200
}
201201

202-
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
203202
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
204203
impl cmp::Ord for Alignment {
205204
#[inline]
@@ -208,7 +207,6 @@ impl cmp::Ord for Alignment {
208207
}
209208
}
210209

211-
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
212210
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
213211
impl cmp::PartialOrd for Alignment {
214212
#[inline]

0 commit comments

Comments
 (0)