Skip to content

Commit 327cfb6

Browse files
committed
rust: upgrade to Rust 1.70.0
`rust-next` is getting Rust 1.70.0 soon, thus upgrade it here too (with the extra `alloc` bits, as usual). This also aligns all branches to a single Rust version. Signed-off-by: Miguel Ojeda <[email protected]>
1 parent bc22545 commit 327cfb6

File tree

22 files changed

+473
-757
lines changed

22 files changed

+473
-757
lines changed

Documentation/process/changes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ you probably needn't concern yourself with pcmciautils.
3131
====================== =============== ========================================
3232
GNU C 5.1 gcc --version
3333
Clang/LLVM (optional) 11.0.0 clang --version
34-
Rust (optional) 1.66.0 rustc --version
34+
Rust (optional) 1.70.0 rustc --version
3535
bindgen (optional) 0.56.0 bindgen --version
3636
GNU make 3.82 make --version
3737
bash 4.2 bash --version

rust/alloc/alloc.rs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,28 @@ use core::ptr::{self, NonNull};
1616
#[doc(inline)]
1717
pub use core::alloc::*;
1818

19-
use core::marker::Destruct;
20-
2119
#[cfg(test)]
2220
mod tests;
2321

2422
extern "Rust" {
25-
// These are the magic symbols to call the global allocator. rustc generates
23+
// These are the magic symbols to call the global allocator. rustc generates
2624
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
2725
// (the code expanding that attribute macro generates those functions), or to call
28-
// the default implementations in libstd (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
26+
// the default implementations in std (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
2927
// otherwise.
3028
// The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them
3129
// like `malloc`, `realloc`, and `free`, respectively.
3230
#[rustc_allocator]
33-
#[cfg_attr(not(bootstrap), rustc_nounwind)]
34-
#[cfg_attr(bootstrap, rustc_allocator_nounwind)]
31+
#[rustc_nounwind]
3532
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
3633
#[rustc_deallocator]
37-
#[cfg_attr(not(bootstrap), rustc_nounwind)]
38-
#[cfg_attr(bootstrap, rustc_allocator_nounwind)]
34+
#[rustc_nounwind]
3935
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
4036
#[rustc_reallocator]
41-
#[cfg_attr(not(bootstrap), rustc_nounwind)]
42-
#[cfg_attr(bootstrap, rustc_allocator_nounwind)]
37+
#[rustc_nounwind]
4338
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
4439
#[rustc_allocator_zeroed]
45-
#[cfg_attr(not(bootstrap), rustc_nounwind)]
46-
#[cfg_attr(bootstrap, rustc_allocator_nounwind)]
40+
#[rustc_nounwind]
4741
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
4842
}
4943

@@ -337,16 +331,12 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
337331

338332
#[cfg_attr(not(test), lang = "box_free")]
339333
#[inline]
340-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
341334
// This signature has to be the same as `Box`, otherwise an ICE will happen.
342335
// When an additional parameter to `Box` is added (like `A: Allocator`), this has to be added here as
343336
// well.
344337
// For example if `Box` is changed to `struct Box<T: ?Sized, A: Allocator>(Unique<T>, A)`,
345338
// this function has to be changed to `fn box_free<T: ?Sized, A: Allocator>(Unique<T>, A)` as well.
346-
pub(crate) const unsafe fn box_free<T: ?Sized, A: ~const Allocator + ~const Destruct>(
347-
ptr: Unique<T>,
348-
alloc: A,
349-
) {
339+
pub(crate) unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: Unique<T>, alloc: A) {
350340
unsafe {
351341
let size = size_of_val(ptr.as_ref());
352342
let align = min_align_of_val(ptr.as_ref());
@@ -359,7 +349,7 @@ pub(crate) const unsafe fn box_free<T: ?Sized, A: ~const Allocator + ~const Dest
359349

360350
#[cfg(not(no_global_oom_handling))]
361351
extern "Rust" {
362-
// This is the magic symbol to call the global alloc error handler. rustc generates
352+
// This is the magic symbol to call the global alloc error handler. rustc generates
363353
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
364354
// default implementations below (`__rdl_oom`) otherwise.
365355
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
@@ -404,25 +394,24 @@ pub use std::alloc::handle_alloc_error;
404394
#[allow(unused_attributes)]
405395
#[unstable(feature = "alloc_internals", issue = "none")]
406396
pub mod __alloc_error_handler {
407-
use crate::alloc::Layout;
408-
409-
// called via generated `__rust_alloc_error_handler`
410-
411-
// if there is no `#[alloc_error_handler]`
397+
// called via generated `__rust_alloc_error_handler` if there is no
398+
// `#[alloc_error_handler]`.
412399
#[rustc_std_internal_symbol]
413400
pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
414-
panic!("memory allocation of {size} bytes failed")
415-
}
416-
417-
// if there is an `#[alloc_error_handler]`
418-
#[rustc_std_internal_symbol]
419-
pub unsafe fn __rg_oom(size: usize, align: usize) -> ! {
420-
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
421401
extern "Rust" {
422-
#[lang = "oom"]
423-
fn oom_impl(layout: Layout) -> !;
402+
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
403+
// Its value depends on the -Zoom={panic,abort} compiler option.
404+
static __rust_alloc_error_handler_should_panic: u8;
405+
}
406+
407+
#[allow(unused_unsafe)]
408+
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
409+
panic!("memory allocation of {size} bytes failed")
410+
} else {
411+
core::panicking::panic_nounwind_fmt(format_args!(
412+
"memory allocation of {size} bytes failed"
413+
))
424414
}
425-
unsafe { oom_impl(layout) }
426415
}
427416
}
428417

rust/alloc/borrow.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,9 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
330330
}
331331

332332
#[stable(feature = "rust1", since = "1.0.0")]
333-
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
334-
impl<B: ?Sized + ToOwned> const Deref for Cow<'_, B>
333+
impl<B: ?Sized + ToOwned> Deref for Cow<'_, B>
335334
where
336-
B::Owned: ~const Borrow<B>,
335+
B::Owned: Borrow<B>,
337336
{
338337
type Target = B;
339338

rust/alloc/boxed.rs

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,13 @@ use core::any::Any;
152152
use core::async_iter::AsyncIterator;
153153
use core::borrow;
154154
use core::cmp::Ordering;
155-
use core::convert::{From, TryFrom};
156155
use core::error::Error;
157156
use core::fmt;
158157
use core::future::Future;
159158
use core::hash::{Hash, Hasher};
160-
#[cfg(not(no_global_oom_handling))]
161-
use core::iter::FromIterator;
162-
use core::iter::{FusedIterator, Iterator};
163-
use core::marker::{Destruct, Unpin, Unsize};
159+
use core::iter::FusedIterator;
160+
use core::marker::Tuple;
161+
use core::marker::Unsize;
164162
use core::mem;
165163
use core::ops::{
166164
CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver,
@@ -187,7 +185,7 @@ pub use thin::ThinBox;
187185

188186
mod thin;
189187

190-
/// A pointer type for heap allocation.
188+
/// A pointer type that uniquely owns a heap allocation of type `T`.
191189
///
192190
/// See the [module-level documentation](../../std/boxed/index.html) for more.
193191
#[lang = "owned_box"]
@@ -215,6 +213,7 @@ impl<T> Box<T> {
215213
#[inline(always)]
216214
#[stable(feature = "rust1", since = "1.0.0")]
217215
#[must_use]
216+
#[rustc_diagnostic_item = "box_new"]
218217
pub fn new(x: T) -> Self {
219218
#[rustc_box]
220219
Box::new(x)
@@ -284,9 +283,7 @@ impl<T> Box<T> {
284283
#[must_use]
285284
#[inline(always)]
286285
pub fn pin(x: T) -> Pin<Box<T>> {
287-
(#[rustc_box]
288-
Box::new(x))
289-
.into()
286+
Box::new(x).into()
290287
}
291288

292289
/// Allocates memory on the heap then places `x` into it,
@@ -378,12 +375,11 @@ impl<T, A: Allocator> Box<T, A> {
378375
/// ```
379376
#[cfg(not(no_global_oom_handling))]
380377
#[unstable(feature = "allocator_api", issue = "32838")]
381-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
382378
#[must_use]
383379
#[inline]
384-
pub const fn new_in(x: T, alloc: A) -> Self
380+
pub fn new_in(x: T, alloc: A) -> Self
385381
where
386-
A: ~const Allocator + ~const Destruct,
382+
A: Allocator,
387383
{
388384
let mut boxed = Self::new_uninit_in(alloc);
389385
unsafe {
@@ -408,12 +404,10 @@ impl<T, A: Allocator> Box<T, A> {
408404
/// # Ok::<(), std::alloc::AllocError>(())
409405
/// ```
410406
#[unstable(feature = "allocator_api", issue = "32838")]
411-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
412407
#[inline]
413-
pub const fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>
408+
pub fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>
414409
where
415-
T: ~const Destruct,
416-
A: ~const Allocator + ~const Destruct,
410+
A: Allocator,
417411
{
418412
let mut boxed = Self::try_new_uninit_in(alloc)?;
419413
unsafe {
@@ -443,13 +437,12 @@ impl<T, A: Allocator> Box<T, A> {
443437
/// assert_eq!(*five, 5)
444438
/// ```
445439
#[unstable(feature = "allocator_api", issue = "32838")]
446-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
447440
#[cfg(not(no_global_oom_handling))]
448441
#[must_use]
449442
// #[unstable(feature = "new_uninit", issue = "63291")]
450-
pub const fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A>
443+
pub fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A>
451444
where
452-
A: ~const Allocator + ~const Destruct,
445+
A: Allocator,
453446
{
454447
let layout = Layout::new::<mem::MaybeUninit<T>>();
455448
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -484,10 +477,9 @@ impl<T, A: Allocator> Box<T, A> {
484477
/// ```
485478
#[unstable(feature = "allocator_api", issue = "32838")]
486479
// #[unstable(feature = "new_uninit", issue = "63291")]
487-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
488-
pub const fn try_new_uninit_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError>
480+
pub fn try_new_uninit_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError>
489481
where
490-
A: ~const Allocator + ~const Destruct,
482+
A: Allocator,
491483
{
492484
let layout = Layout::new::<mem::MaybeUninit<T>>();
493485
let ptr = alloc.allocate(layout)?.cast();
@@ -515,13 +507,12 @@ impl<T, A: Allocator> Box<T, A> {
515507
///
516508
/// [zeroed]: mem::MaybeUninit::zeroed
517509
#[unstable(feature = "allocator_api", issue = "32838")]
518-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
519510
#[cfg(not(no_global_oom_handling))]
520511
// #[unstable(feature = "new_uninit", issue = "63291")]
521512
#[must_use]
522-
pub const fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A>
513+
pub fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A>
523514
where
524-
A: ~const Allocator + ~const Destruct,
515+
A: Allocator,
525516
{
526517
let layout = Layout::new::<mem::MaybeUninit<T>>();
527518
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -556,10 +547,9 @@ impl<T, A: Allocator> Box<T, A> {
556547
/// [zeroed]: mem::MaybeUninit::zeroed
557548
#[unstable(feature = "allocator_api", issue = "32838")]
558549
// #[unstable(feature = "new_uninit", issue = "63291")]
559-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
560-
pub const fn try_new_zeroed_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError>
550+
pub fn try_new_zeroed_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError>
561551
where
562-
A: ~const Allocator + ~const Destruct,
552+
A: Allocator,
563553
{
564554
let layout = Layout::new::<mem::MaybeUninit<T>>();
565555
let ptr = alloc.allocate_zeroed(layout)?.cast();
@@ -575,12 +565,11 @@ impl<T, A: Allocator> Box<T, A> {
575565
/// construct a (pinned) `Box` in a different way than with [`Box::new_in`].
576566
#[cfg(not(no_global_oom_handling))]
577567
#[unstable(feature = "allocator_api", issue = "32838")]
578-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
579568
#[must_use]
580569
#[inline(always)]
581-
pub const fn pin_in(x: T, alloc: A) -> Pin<Self>
570+
pub fn pin_in(x: T, alloc: A) -> Pin<Self>
582571
where
583-
A: 'static + ~const Allocator + ~const Destruct,
572+
A: 'static + Allocator,
584573
{
585574
Self::into_pin(Self::new_in(x, alloc))
586575
}
@@ -607,12 +596,8 @@ impl<T, A: Allocator> Box<T, A> {
607596
/// assert_eq!(Box::into_inner(c), 5);
608597
/// ```
609598
#[unstable(feature = "box_into_inner", issue = "80437")]
610-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
611599
#[inline]
612-
pub const fn into_inner(boxed: Self) -> T
613-
where
614-
Self: ~const Destruct,
615-
{
600+
pub fn into_inner(boxed: Self) -> T {
616601
*boxed
617602
}
618603
}
@@ -954,7 +939,7 @@ impl<T: ?Sized> Box<T> {
954939
/// [`Layout`]: crate::Layout
955940
#[stable(feature = "box_raw", since = "1.4.0")]
956941
#[inline]
957-
#[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `Box`"]
942+
#[must_use = "call `drop(Box::from_raw(ptr))` if you intend to drop the `Box`"]
958943
pub unsafe fn from_raw(raw: *mut T) -> Self {
959944
unsafe { Self::from_raw_in(raw, Global) }
960945
}
@@ -1243,8 +1228,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
12431228
#[stable(feature = "rust1", since = "1.0.0")]
12441229
impl<T: Default> Default for Box<T> {
12451230
/// Creates a `Box<T>`, with the `Default` value for T.
1231+
#[inline]
12461232
fn default() -> Self {
1247-
#[rustc_box]
12481233
Box::new(T::default())
12491234
}
12501235
}
@@ -1253,6 +1238,7 @@ impl<T: Default> Default for Box<T> {
12531238
#[stable(feature = "rust1", since = "1.0.0")]
12541239
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
12551240
impl<T> const Default for Box<[T]> {
1241+
#[inline]
12561242
fn default() -> Self {
12571243
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
12581244
Box(ptr, Global)
@@ -1263,6 +1249,7 @@ impl<T> const Default for Box<[T]> {
12631249
#[stable(feature = "default_box_extra", since = "1.17.0")]
12641250
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
12651251
impl const Default for Box<str> {
1252+
#[inline]
12661253
fn default() -> Self {
12671254
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
12681255
let ptr: Unique<str> = unsafe {
@@ -1617,7 +1604,6 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
16171604
/// println!("{boxed:?}");
16181605
/// ```
16191606
fn from(array: [T; N]) -> Box<[T]> {
1620-
#[rustc_box]
16211607
Box::new(array)
16221608
}
16231609
}
@@ -1982,7 +1968,7 @@ impl<I: ExactSizeIterator + ?Sized, A: Allocator> ExactSizeIterator for Box<I, A
19821968
impl<I: FusedIterator + ?Sized, A: Allocator> FusedIterator for Box<I, A> {}
19831969

19841970
#[stable(feature = "boxed_closure_impls", since = "1.35.0")]
1985-
impl<Args, F: FnOnce<Args> + ?Sized, A: Allocator> FnOnce<Args> for Box<F, A> {
1971+
impl<Args: Tuple, F: FnOnce<Args> + ?Sized, A: Allocator> FnOnce<Args> for Box<F, A> {
19861972
type Output = <F as FnOnce<Args>>::Output;
19871973

19881974
extern "rust-call" fn call_once(self, args: Args) -> Self::Output {
@@ -1991,20 +1977,20 @@ impl<Args, F: FnOnce<Args> + ?Sized, A: Allocator> FnOnce<Args> for Box<F, A> {
19911977
}
19921978

19931979
#[stable(feature = "boxed_closure_impls", since = "1.35.0")]
1994-
impl<Args, F: FnMut<Args> + ?Sized, A: Allocator> FnMut<Args> for Box<F, A> {
1980+
impl<Args: Tuple, F: FnMut<Args> + ?Sized, A: Allocator> FnMut<Args> for Box<F, A> {
19951981
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output {
19961982
<F as FnMut<Args>>::call_mut(self, args)
19971983
}
19981984
}
19991985

20001986
#[stable(feature = "boxed_closure_impls", since = "1.35.0")]
2001-
impl<Args, F: Fn<Args> + ?Sized, A: Allocator> Fn<Args> for Box<F, A> {
1987+
impl<Args: Tuple, F: Fn<Args> + ?Sized, A: Allocator> Fn<Args> for Box<F, A> {
20021988
extern "rust-call" fn call(&self, args: Args) -> Self::Output {
20031989
<F as Fn<Args>>::call(self, args)
20041990
}
20051991
}
20061992

2007-
#[unstable(feature = "coerce_unsized", issue = "27732")]
1993+
#[unstable(feature = "coerce_unsized", issue = "18598")]
20081994
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
20091995

20101996
#[unstable(feature = "dispatch_from_dyn", issue = "none")]

0 commit comments

Comments
 (0)