Skip to content

Commit 73596f5

Browse files
ojedagregkh
authored andcommitted
rust: upgrade to Rust 1.73.0
commit e08ff62 upstream. This is the next upgrade to the Rust toolchain, from 1.72.1 to 1.73.0 (i.e. the latest) [1]. See the upgrade policy [2] and the comments on the first upgrade in commit 3ed03f4 ("rust: upgrade to Rust 1.68.2"). # Unstable features No unstable features (that we use) were stabilized. Therefore, the only unstable feature allowed to be used outside the `kernel` crate is still `new_uninit`, though other code to be upstreamed may increase the list. Please see [3] for details. # Required changes For the upgrade, the following changes are required: - Allow `internal_features` for `feature(compiler_builtins)` since now Rust warns about using internal compiler and standard library features (similar to how it also warns about incomplete ones) [4]. - A cleanup for a documentation link thanks to a new `rustdoc` lint. See previous commits for details. - A need to make an intra-doc link to a macro explicit, due to a change in behavior in `rustdoc`. See previous commits for details. # `alloc` upgrade and reviewing The vast majority of changes are due to our `alloc` fork being upgraded at once. There are two kinds of changes to be aware of: the ones coming from upstream, which we should follow as closely as possible, and the updates needed in our added fallible APIs to keep them matching the newer infallible APIs coming from upstream. Instead of taking a look at the diff of this patch, an alternative approach is reviewing a diff of the changes between upstream `alloc` and the kernel's. This allows to easily inspect the kernel additions only, especially to check if the fallible methods we already have still match the infallible ones in the new version coming from upstream. Another approach is reviewing the changes introduced in the additions in the kernel fork between the two versions. This is useful to spot potentially unintended changes to our additions. To apply these approaches, one may follow steps similar to the following to generate a pair of patches that show the differences between upstream Rust and the kernel (for the subset of `alloc` we use) before and after applying this patch: # Get the difference with respect to the old version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > old.patch git -C linux restore rust/alloc # Apply this patch. git -C linux am rust-upgrade.patch # Get the difference with respect to the new version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > new.patch git -C linux restore rust/alloc Now one may check the `new.patch` to take a look at the additions (first approach) or at the difference between those two patches (second approach). For the latter, a side-by-side tool is recommended. Link: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1730-2023-10-05 [1] Link: https://rust-for-linux.com/rust-version-policy [2] Link: Rust-for-Linux/linux#2 [3] Link: rust-lang/compiler-team#596 [4] Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Vincenzo Palazzo <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent aacae44 commit 73596f5

File tree

9 files changed

+63
-59
lines changed

9 files changed

+63
-59
lines changed

Documentation/process/changes.rst

+1-1
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.72.1 rustc --version
34+
Rust (optional) 1.73.0 rustc --version
3535
bindgen (optional) 0.65.1 bindgen --version
3636
GNU make 3.82 make --version
3737
bash 4.2 bash --version

rust/alloc/alloc.rs

-22
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
#[cfg(not(test))]
88
use core::intrinsics;
9-
#[cfg(all(bootstrap, not(test)))]
10-
use core::intrinsics::{min_align_of_val, size_of_val};
119

12-
#[cfg(all(bootstrap, not(test)))]
13-
use core::ptr::Unique;
1410
#[cfg(not(test))]
1511
use core::ptr::{self, NonNull};
1612

@@ -339,23 +335,6 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
339335
}
340336
}
341337

342-
#[cfg(all(bootstrap, not(test)))]
343-
#[lang = "box_free"]
344-
#[inline]
345-
// This signature has to be the same as `Box`, otherwise an ICE will happen.
346-
// When an additional parameter to `Box` is added (like `A: Allocator`), this has to be added here as
347-
// well.
348-
// For example if `Box` is changed to `struct Box<T: ?Sized, A: Allocator>(Unique<T>, A)`,
349-
// this function has to be changed to `fn box_free<T: ?Sized, A: Allocator>(Unique<T>, A)` as well.
350-
unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: Unique<T>, alloc: A) {
351-
unsafe {
352-
let size = size_of_val(ptr.as_ref());
353-
let align = min_align_of_val(ptr.as_ref());
354-
let layout = Layout::from_size_align_unchecked(size, align);
355-
alloc.deallocate(From::from(ptr.cast()), layout)
356-
}
357-
}
358-
359338
// # Allocation error handler
360339

361340
#[cfg(not(no_global_oom_handling))]
@@ -415,7 +394,6 @@ pub mod __alloc_error_handler {
415394
static __rust_alloc_error_handler_should_panic: u8;
416395
}
417396

418-
#[allow(unused_unsafe)]
419397
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
420398
panic!("memory allocation of {size} bytes failed")
421399
} else {

rust/alloc/boxed.rs

+31-17
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ use core::hash::{Hash, Hasher};
159159
use core::iter::FusedIterator;
160160
use core::marker::Tuple;
161161
use core::marker::Unsize;
162-
use core::mem;
162+
use core::mem::{self, SizedTypeProperties};
163163
use core::ops::{
164164
CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver,
165165
};
166166
use core::pin::Pin;
167-
use core::ptr::{self, Unique};
167+
use core::ptr::{self, NonNull, Unique};
168168
use core::task::{Context, Poll};
169169

170170
#[cfg(not(no_global_oom_handling))]
@@ -483,8 +483,12 @@ impl<T, A: Allocator> Box<T, A> {
483483
where
484484
A: Allocator,
485485
{
486-
let layout = Layout::new::<mem::MaybeUninit<T>>();
487-
let ptr = alloc.allocate(layout)?.cast();
486+
let ptr = if T::IS_ZST {
487+
NonNull::dangling()
488+
} else {
489+
let layout = Layout::new::<mem::MaybeUninit<T>>();
490+
alloc.allocate(layout)?.cast()
491+
};
488492
unsafe { Ok(Box::from_raw_in(ptr.as_ptr(), alloc)) }
489493
}
490494

@@ -553,8 +557,12 @@ impl<T, A: Allocator> Box<T, A> {
553557
where
554558
A: Allocator,
555559
{
556-
let layout = Layout::new::<mem::MaybeUninit<T>>();
557-
let ptr = alloc.allocate_zeroed(layout)?.cast();
560+
let ptr = if T::IS_ZST {
561+
NonNull::dangling()
562+
} else {
563+
let layout = Layout::new::<mem::MaybeUninit<T>>();
564+
alloc.allocate_zeroed(layout)?.cast()
565+
};
558566
unsafe { Ok(Box::from_raw_in(ptr.as_ptr(), alloc)) }
559567
}
560568

@@ -679,14 +687,16 @@ impl<T> Box<[T]> {
679687
#[unstable(feature = "allocator_api", issue = "32838")]
680688
#[inline]
681689
pub fn try_new_uninit_slice(len: usize) -> Result<Box<[mem::MaybeUninit<T>]>, AllocError> {
682-
unsafe {
690+
let ptr = if T::IS_ZST || len == 0 {
691+
NonNull::dangling()
692+
} else {
683693
let layout = match Layout::array::<mem::MaybeUninit<T>>(len) {
684694
Ok(l) => l,
685695
Err(_) => return Err(AllocError),
686696
};
687-
let ptr = Global.allocate(layout)?;
688-
Ok(RawVec::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len))
689-
}
697+
Global.allocate(layout)?.cast()
698+
};
699+
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, Global).into_box(len)) }
690700
}
691701

692702
/// Constructs a new boxed slice with uninitialized contents, with the memory
@@ -711,14 +721,16 @@ impl<T> Box<[T]> {
711721
#[unstable(feature = "allocator_api", issue = "32838")]
712722
#[inline]
713723
pub fn try_new_zeroed_slice(len: usize) -> Result<Box<[mem::MaybeUninit<T>]>, AllocError> {
714-
unsafe {
724+
let ptr = if T::IS_ZST || len == 0 {
725+
NonNull::dangling()
726+
} else {
715727
let layout = match Layout::array::<mem::MaybeUninit<T>>(len) {
716728
Ok(l) => l,
717729
Err(_) => return Err(AllocError),
718730
};
719-
let ptr = Global.allocate_zeroed(layout)?;
720-
Ok(RawVec::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len))
721-
}
731+
Global.allocate_zeroed(layout)?.cast()
732+
};
733+
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, Global).into_box(len)) }
722734
}
723735
}
724736

@@ -1223,7 +1235,9 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
12231235

12241236
unsafe {
12251237
let layout = Layout::for_value_raw(ptr.as_ptr());
1226-
self.1.deallocate(From::from(ptr.cast()), layout)
1238+
if layout.size() != 0 {
1239+
self.1.deallocate(From::from(ptr.cast()), layout);
1240+
}
12271241
}
12281242
}
12291243
}
@@ -2173,7 +2187,7 @@ impl dyn Error + Send {
21732187
let err: Box<dyn Error> = self;
21742188
<dyn Error>::downcast(err).map_err(|s| unsafe {
21752189
// Reapply the `Send` marker.
2176-
mem::transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s)
2190+
Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send))
21772191
})
21782192
}
21792193
}
@@ -2187,7 +2201,7 @@ impl dyn Error + Send + Sync {
21872201
let err: Box<dyn Error> = self;
21882202
<dyn Error>::downcast(err).map_err(|s| unsafe {
21892203
// Reapply the `Send + Sync` marker.
2190-
mem::transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s)
2204+
Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send + Sync))
21912205
})
21922206
}
21932207
}

rust/alloc/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
6161
// To run alloc tests without x.py without ending up with two copies of alloc, Miri needs to be
6262
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
63-
// rustc itself never sets the feature, so this line has no affect there.
63+
// rustc itself never sets the feature, so this line has no effect there.
6464
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
6565
//
6666
#![allow(unused_attributes)]
@@ -90,6 +90,8 @@
9090
#![warn(missing_docs)]
9191
#![allow(explicit_outlives_requirements)]
9292
#![warn(multiple_supertrait_upcastable)]
93+
#![cfg_attr(not(bootstrap), allow(internal_features))]
94+
#![cfg_attr(not(bootstrap), allow(rustdoc::redundant_explicit_links))]
9395
//
9496
// Library features:
9597
// tidy-alphabetical-start
@@ -139,7 +141,6 @@
139141
#![feature(maybe_uninit_uninit_array_transpose)]
140142
#![feature(pattern)]
141143
#![feature(pointer_byte_offsets)]
142-
#![feature(provide_any)]
143144
#![feature(ptr_internals)]
144145
#![feature(ptr_metadata)]
145146
#![feature(ptr_sub_ptr)]

rust/alloc/raw_vec.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,26 @@ impl<T, A: Allocator> RawVec<T, A> {
471471
let (ptr, layout) = if let Some(mem) = self.current_memory() { mem } else { return Ok(()) };
472472
// See current_memory() why this assert is here
473473
let _: () = const { assert!(mem::size_of::<T>() % mem::align_of::<T>() == 0) };
474-
let ptr = unsafe {
475-
// `Layout::array` cannot overflow here because it would have
476-
// overflowed earlier when capacity was larger.
477-
let new_size = mem::size_of::<T>().unchecked_mul(cap);
478-
let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
479-
self.alloc
480-
.shrink(ptr, layout, new_layout)
481-
.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })?
482-
};
483-
self.set_ptr_and_cap(ptr, cap);
474+
475+
// If shrinking to 0, deallocate the buffer. We don't reach this point
476+
// for the T::IS_ZST case since current_memory() will have returned
477+
// None.
478+
if cap == 0 {
479+
unsafe { self.alloc.deallocate(ptr, layout) };
480+
self.ptr = Unique::dangling();
481+
self.cap = 0;
482+
} else {
483+
let ptr = unsafe {
484+
// `Layout::array` cannot overflow here because it would have
485+
// overflowed earlier when capacity was larger.
486+
let new_size = mem::size_of::<T>().unchecked_mul(cap);
487+
let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
488+
self.alloc
489+
.shrink(ptr, layout, new_layout)
490+
.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })?
491+
};
492+
self.set_ptr_and_cap(ptr, cap);
493+
}
484494
Ok(())
485495
}
486496
}

rust/alloc/vec/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ mod spec_extend;
216216
///
217217
/// # Indexing
218218
///
219-
/// The `Vec` type allows to access values by index, because it implements the
219+
/// The `Vec` type allows access to values by index, because it implements the
220220
/// [`Index`] trait. An example will be more explicit:
221221
///
222222
/// ```
@@ -3263,7 +3263,7 @@ impl<T, A: Allocator> Vec<T, A> {
32633263
/// [`copy_from_slice`]: slice::copy_from_slice
32643264
#[cfg(not(no_global_oom_handling))]
32653265
#[stable(feature = "extend_ref", since = "1.2.0")]
3266-
impl<'a, T: Copy + 'a, A: Allocator + 'a> Extend<&'a T> for Vec<T, A> {
3266+
impl<'a, T: Copy + 'a, A: Allocator> Extend<&'a T> for Vec<T, A> {
32673267
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
32683268
self.spec_extend(iter.into_iter())
32693269
}

rust/alloc/vec/spec_extend.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<T, A: Allocator> TrySpecExtend<T, IntoIter<T>> for Vec<T, A> {
7777
}
7878

7979
#[cfg(not(no_global_oom_handling))]
80-
impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec<T, A>
80+
impl<'a, T: 'a, I, A: Allocator> SpecExtend<&'a T, I> for Vec<T, A>
8181
where
8282
I: Iterator<Item = &'a T>,
8383
T: Clone,
@@ -87,7 +87,7 @@ where
8787
}
8888
}
8989

90-
impl<'a, T: 'a, I, A: Allocator + 'a> TrySpecExtend<&'a T, I> for Vec<T, A>
90+
impl<'a, T: 'a, I, A: Allocator> TrySpecExtend<&'a T, I> for Vec<T, A>
9191
where
9292
I: Iterator<Item = &'a T>,
9393
T: Clone,
@@ -98,7 +98,7 @@ where
9898
}
9999

100100
#[cfg(not(no_global_oom_handling))]
101-
impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A>
101+
impl<'a, T: 'a, A: Allocator> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A>
102102
where
103103
T: Copy,
104104
{
@@ -108,7 +108,7 @@ where
108108
}
109109
}
110110

111-
impl<'a, T: 'a, A: Allocator + 'a> TrySpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A>
111+
impl<'a, T: 'a, A: Allocator> TrySpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A>
112112
where
113113
T: Copy,
114114
{

rust/compiler_builtins.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! [`compiler_builtins`]: https://github.com/rust-lang/compiler-builtins
2020
//! [`compiler-rt`]: https://compiler-rt.llvm.org/
2121
22+
#![allow(internal_features)]
2223
#![feature(compiler_builtins)]
2324
#![compiler_builtins]
2425
#![no_builtins]

scripts/min-tool-version.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ llvm)
3131
fi
3232
;;
3333
rustc)
34-
echo 1.72.1
34+
echo 1.73.0
3535
;;
3636
bindgen)
3737
echo 0.65.1

0 commit comments

Comments
 (0)