Skip to content

Commit a10a96a

Browse files
ojedaintel-lab-lkp
authored andcommitted
rust: upgrade to Rust 1.74.1
This is the next upgrade to the Rust toolchain, from 1.73.0 to 1.74.1 (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 features allowed to be used outside the `kernel` crate are still `new_uninit,offset_of`, though other code to be upstreamed may increase the list (e.g. `offset_of` was added recently). Please see [3] for details. # Other improvements Rust 1.74.0 allows to use `#[repr(Rust)]` explicitly [4], which can be useful to be explicit about particular cases that would normally use e.g. the C representation, such as silencing lints like the upcoming additions we requested [5] to the `no_mangle_with_rust_abi` Clippy lint (which in turn triggered the `#[repr(Rust)]` addition). Rust 1.74.0 includes a fix for one of the false negative cases we reported in Clippy's `disallowed_macros` lint [6] that we would like to use in the future. Rust 1.74.1 fixes an ICE that the Apple AGX GPU driver was hitting [7]. # Required changes For this upgrade, no changes were required (i.e. on our side). # `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-1741-2023-12-07 [1] Link: https://rust-for-linux.com/rust-version-policy [2] Link: Rust-for-Linux#2 [3] Link: rust-lang/rust#114201 [4] Link: rust-lang/rust-clippy#11219 [5] Link: rust-lang/rust-clippy#11431 [6] Link: rust-lang/rust#117976 (comment) [7] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent a39b6ac commit a10a96a

File tree

6 files changed

+114
-17
lines changed

6 files changed

+114
-17
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.73.0 rustc --version
34+
Rust (optional) 1.74.1 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

+23-9
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,31 @@ extern "Rust" {
345345
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
346346
}
347347

348-
/// Abort on memory allocation error or failure.
348+
/// Signal a memory allocation error.
349349
///
350-
/// Callers of memory allocation APIs wishing to abort computation
350+
/// Callers of memory allocation APIs wishing to cease execution
351351
/// in response to an allocation error are encouraged to call this function,
352-
/// rather than directly invoking `panic!` or similar.
352+
/// rather than directly invoking [`panic!`] or similar.
353353
///
354-
/// The default behavior of this function is to print a message to standard error
355-
/// and abort the process.
356-
/// It can be replaced with [`set_alloc_error_hook`] and [`take_alloc_error_hook`].
354+
/// This function is guaranteed to diverge (not return normally with a value), but depending on
355+
/// global configuration, it may either panic (resulting in unwinding or aborting as per
356+
/// configuration for all panics), or abort the process (with no unwinding).
357+
///
358+
/// The default behavior is:
359+
///
360+
/// * If the binary links against `std` (typically the case), then
361+
/// print a message to standard error and abort the process.
362+
/// This behavior can be replaced with [`set_alloc_error_hook`] and [`take_alloc_error_hook`].
363+
/// Future versions of Rust may panic by default instead.
364+
///
365+
/// * If the binary does not link against `std` (all of its crates are marked
366+
/// [`#![no_std]`][no_std]), then call [`panic!`] with a message.
367+
/// [The panic handler] applies as to any panic.
357368
///
358369
/// [`set_alloc_error_hook`]: ../../std/alloc/fn.set_alloc_error_hook.html
359370
/// [`take_alloc_error_hook`]: ../../std/alloc/fn.take_alloc_error_hook.html
371+
/// [The panic handler]: https://doc.rust-lang.org/reference/runtime.html#the-panic_handler-attribute
372+
/// [no_std]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute
360373
#[stable(feature = "global_alloc", since = "1.28.0")]
361374
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
362375
#[cfg(all(not(no_global_oom_handling), not(test)))]
@@ -397,9 +410,10 @@ pub mod __alloc_error_handler {
397410
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
398411
panic!("memory allocation of {size} bytes failed")
399412
} else {
400-
core::panicking::panic_nounwind_fmt(format_args!(
401-
"memory allocation of {size} bytes failed"
402-
))
413+
core::panicking::panic_nounwind_fmt(
414+
format_args!("memory allocation of {size} bytes failed"),
415+
/* force_no_backtrace */ false,
416+
)
403417
}
404418
}
405419
}

rust/alloc/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,8 +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))]
93+
#![allow(internal_features)]
94+
#![allow(rustdoc::redundant_explicit_links)]
9595
//
9696
// Library features:
9797
// tidy-alphabetical-start
@@ -122,6 +122,7 @@
122122
#![feature(const_waker)]
123123
#![feature(core_intrinsics)]
124124
#![feature(core_panic)]
125+
#![feature(deprecated_suggestion)]
125126
#![feature(dispatch_from_dyn)]
126127
#![feature(error_generic_member_access)]
127128
#![feature(error_in_core)]
@@ -145,7 +146,6 @@
145146
#![feature(ptr_metadata)]
146147
#![feature(ptr_sub_ptr)]
147148
#![feature(receiver_trait)]
148-
#![feature(saturating_int_impl)]
149149
#![feature(set_ptr_value)]
150150
#![feature(sized_type_properties)]
151151
#![feature(slice_from_ptr_range)]

rust/alloc/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl<T> [T] {
594594
/// ```
595595
#[rustc_allow_incoherent_impl]
596596
#[stable(feature = "rust1", since = "1.0.0")]
597-
#[deprecated(since = "1.3.0", note = "renamed to join")]
597+
#[deprecated(since = "1.3.0", note = "renamed to join", suggestion = "join")]
598598
pub fn connect<Separator>(&self, sep: Separator) -> <Self as Join<Separator>>::Output
599599
where
600600
Self: Join<Separator>,

rust/alloc/vec/mod.rs

+85-2
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,8 @@ impl<T, A: Allocator> Vec<T, A> {
12281228
/// Shortens the vector, keeping the first `len` elements and dropping
12291229
/// the rest.
12301230
///
1231-
/// If `len` is greater than the vector's current length, this has no
1232-
/// effect.
1231+
/// If `len` is greater or equal to the vector's current length, this has
1232+
/// no effect.
12331233
///
12341234
/// The [`drain`] method can emulate `truncate`, but causes the excess
12351235
/// elements to be returned instead of dropped.
@@ -1336,6 +1336,15 @@ impl<T, A: Allocator> Vec<T, A> {
13361336
/// is never written to (except inside an `UnsafeCell`) using this pointer or any pointer
13371337
/// derived from it. If you need to mutate the contents of the slice, use [`as_mut_ptr`].
13381338
///
1339+
/// This method guarantees that for the purpose of the aliasing model, this method
1340+
/// does not materialize a reference to the underlying slice, and thus the returned pointer
1341+
/// will remain valid when mixed with other calls to [`as_ptr`] and [`as_mut_ptr`].
1342+
/// Note that calling other methods that materialize mutable references to the slice,
1343+
/// or mutable references to specific elements you are planning on accessing through this pointer,
1344+
/// as well as writing to those elements, may still invalidate this pointer.
1345+
/// See the second example below for how this guarantee can be used.
1346+
///
1347+
///
13391348
/// # Examples
13401349
///
13411350
/// ```
@@ -1349,8 +1358,25 @@ impl<T, A: Allocator> Vec<T, A> {
13491358
/// }
13501359
/// ```
13511360
///
1361+
/// Due to the aliasing guarantee, the following code is legal:
1362+
///
1363+
/// ```rust
1364+
/// unsafe {
1365+
/// let mut v = vec![0, 1, 2];
1366+
/// let ptr1 = v.as_ptr();
1367+
/// let _ = ptr1.read();
1368+
/// let ptr2 = v.as_mut_ptr().offset(2);
1369+
/// ptr2.write(2);
1370+
/// // Notably, the write to `ptr2` did *not* invalidate `ptr1`
1371+
/// // because it mutated a different element:
1372+
/// let _ = ptr1.read();
1373+
/// }
1374+
/// ```
1375+
///
13521376
/// [`as_mut_ptr`]: Vec::as_mut_ptr
1377+
/// [`as_ptr`]: Vec::as_ptr
13531378
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
1379+
#[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)]
13541380
#[inline]
13551381
pub fn as_ptr(&self) -> *const T {
13561382
// We shadow the slice method of the same name to avoid going through
@@ -1366,6 +1392,15 @@ impl<T, A: Allocator> Vec<T, A> {
13661392
/// Modifying the vector may cause its buffer to be reallocated,
13671393
/// which would also make any pointers to it invalid.
13681394
///
1395+
/// This method guarantees that for the purpose of the aliasing model, this method
1396+
/// does not materialize a reference to the underlying slice, and thus the returned pointer
1397+
/// will remain valid when mixed with other calls to [`as_ptr`] and [`as_mut_ptr`].
1398+
/// Note that calling other methods that materialize references to the slice,
1399+
/// or references to specific elements you are planning on accessing through this pointer,
1400+
/// may still invalidate this pointer.
1401+
/// See the second example below for how this guarantee can be used.
1402+
///
1403+
///
13691404
/// # Examples
13701405
///
13711406
/// ```
@@ -1383,7 +1418,25 @@ impl<T, A: Allocator> Vec<T, A> {
13831418
/// }
13841419
/// assert_eq!(&*x, &[0, 1, 2, 3]);
13851420
/// ```
1421+
///
1422+
/// Due to the aliasing guarantee, the following code is legal:
1423+
///
1424+
/// ```rust
1425+
/// unsafe {
1426+
/// let mut v = vec![0];
1427+
/// let ptr1 = v.as_mut_ptr();
1428+
/// ptr1.write(1);
1429+
/// let ptr2 = v.as_mut_ptr();
1430+
/// ptr2.write(2);
1431+
/// // Notably, the write to `ptr2` did *not* invalidate `ptr1`:
1432+
/// ptr1.write(3);
1433+
/// }
1434+
/// ```
1435+
///
1436+
/// [`as_mut_ptr`]: Vec::as_mut_ptr
1437+
/// [`as_ptr`]: Vec::as_ptr
13861438
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
1439+
#[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)]
13871440
#[inline]
13881441
pub fn as_mut_ptr(&mut self) -> *mut T {
13891442
// We shadow the slice method of the same name to avoid going through
@@ -3403,6 +3456,36 @@ impl<T: Clone> From<&mut [T]> for Vec<T> {
34033456
}
34043457
}
34053458

3459+
#[cfg(not(no_global_oom_handling))]
3460+
#[stable(feature = "vec_from_array_ref", since = "1.74.0")]
3461+
impl<T: Clone, const N: usize> From<&[T; N]> for Vec<T> {
3462+
/// Allocate a `Vec<T>` and fill it by cloning `s`'s items.
3463+
///
3464+
/// # Examples
3465+
///
3466+
/// ```
3467+
/// assert_eq!(Vec::from(&[1, 2, 3]), vec![1, 2, 3]);
3468+
/// ```
3469+
fn from(s: &[T; N]) -> Vec<T> {
3470+
Self::from(s.as_slice())
3471+
}
3472+
}
3473+
3474+
#[cfg(not(no_global_oom_handling))]
3475+
#[stable(feature = "vec_from_array_ref", since = "1.74.0")]
3476+
impl<T: Clone, const N: usize> From<&mut [T; N]> for Vec<T> {
3477+
/// Allocate a `Vec<T>` and fill it by cloning `s`'s items.
3478+
///
3479+
/// # Examples
3480+
///
3481+
/// ```
3482+
/// assert_eq!(Vec::from(&mut [1, 2, 3]), vec![1, 2, 3]);
3483+
/// ```
3484+
fn from(s: &mut [T; N]) -> Vec<T> {
3485+
Self::from(s.as_mut_slice())
3486+
}
3487+
}
3488+
34063489
#[cfg(not(no_global_oom_handling))]
34073490
#[stable(feature = "vec_from_array", since = "1.44.0")]
34083491
impl<T, const N: usize> From<[T; N]> for Vec<T> {

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.73.0
34+
echo 1.74.1
3535
;;
3636
bindgen)
3737
echo 0.65.1

0 commit comments

Comments
 (0)