Skip to content

Commit a1257b5

Browse files
committed
Pull rust updates from Miguel Ojeda: "A fairly small one in terms of feature additions. Most of the changes in terms of lines come from the upgrade to the new version of the toolchain (which in turn is big due to the vendored 'alloc' crate). Upgrade to Rust 1.68.2: - This is the first such upgrade, and we will try to update it often from now on, in order to remain close to the latest release, until a minimum version (which is "in the future") can be established. The upgrade brings the stabilization of 4 features we used (and 2 more that we used in our old 'rust' branch). Commit 3ed03f4 ("rust: upgrade to Rust 1.68.2") contains the details and rationale. pin-init API: - Several internal improvements and fixes to the pin-init API, e.g. allowing to use 'Self' in a struct definition with '#[pin_data]'. 'error' module: - New 'name()' method for the 'Error' type (with 'errname()' integration), used to implement the 'Debug' trait for 'Error'. - Add error codes from 'include/linux/errno.h' to the list of Rust 'Error' constants. - Allow specifying error type on the 'Result' type (with the default still being our usual 'Error' type). 'str' module: - 'TryFrom' implementation for 'CStr', and new 'to_cstring()' method based on it. 'sync' module: - Implement 'AsRef' trait for 'Arc', allowing to use 'Arc' in code that is generic over smart pointer types. - Add 'ptr_eq' method to 'Arc' for easier, less error prone comparison between two 'Arc' pointers. - Reword the 'Send' safety comment for 'Arc', and avoid referencing it from the 'Sync' one. 'task' module: - Implement 'Send' marker for 'Task'. 'types' module: - Implement 'Send' and 'Sync' markers for 'ARef<T>' when 'T' is 'AlwaysRefCounted', 'Send' and 'Sync'. Other changes: - Documentation improvements and '.gitattributes' change to start using the Rust diff driver" * tag 'rust-6.5' of https://github.com/Rust-for-Linux/linux: rust: error: `impl Debug` for `Error` with `errname()` integration rust: task: add `Send` marker to `Task` rust: specify when `ARef` is thread safe rust: sync: reword the `Arc` safety comment for `Sync` rust: sync: reword the `Arc` safety comment for `Send` rust: sync: implement `AsRef<T>` for `Arc<T>` rust: sync: add `Arc::ptr_eq` rust: error: add missing error codes rust: str: add conversion from `CStr` to `CString` rust: error: allow specifying error type on `Result` rust: init: update macro expansion example in docs rust: macros: replace Self with the concrete type in #[pin_data] rust: macros: refactor generics parsing of `#[pin_data]` into its own function rust: macros: fix usage of `#[allow]` in `quote!` docs: rust: point directly to the standalone installers .gitattributes: set diff driver for Rust source code files rust: upgrade to Rust 1.68.2 rust: arc: fix intra-doc link in `Arc<T>::init` rust: alloc: clarify what is the upstream version
2 parents 9d9a9bf + d2e3115 commit a1257b5

36 files changed

+1658
-795
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.[ch] diff=cpp
33
*.dts diff=dts
44
*.dts[io] diff=dts
5+
*.rs diff=rust

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.62.0 rustc --version
34+
Rust (optional) 1.68.2 rustc --version
3535
bindgen (optional) 0.56.0 bindgen --version
3636
GNU make 3.82 make --version
3737
bash 4.2 bash --version

Documentation/rust/quick-start.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ and run::
3838

3939
rustup override set $(scripts/min-tool-version.sh rustc)
4040

41-
Otherwise, fetch a standalone installer or install ``rustup`` from:
41+
Otherwise, fetch a standalone installer from:
4242

43-
https://www.rust-lang.org
43+
https://forge.rust-lang.org/infra/other-installation-methods.html#standalone
4444

4545

4646
Rust standard library source

rust/alloc/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ upstream. In general, only additions should be performed (e.g. new
1010
methods). Eventually, changes should make it into upstream so that,
1111
at some point, this fork can be dropped from the kernel tree.
1212

13+
The Rust upstream version on top of which these files are based matches
14+
the output of `scripts/min-tool-version.sh rustc`.
15+
1316

1417
## Rationale
1518

rust/alloc/alloc.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@ use core::marker::Destruct;
2222
mod tests;
2323

2424
extern "Rust" {
25-
// These are the magic symbols to call the global allocator. rustc generates
25+
// These are the magic symbols to call the global allocator. rustc generates
2626
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
2727
// (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`)
28+
// the default implementations in std (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
2929
// otherwise.
30-
// The rustc fork of LLVM also special-cases these function names to be able to optimize them
30+
// The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them
3131
// like `malloc`, `realloc`, and `free`, respectively.
3232
#[rustc_allocator]
33-
#[rustc_allocator_nounwind]
33+
#[rustc_nounwind]
3434
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
35-
#[rustc_allocator_nounwind]
35+
#[rustc_deallocator]
36+
#[rustc_nounwind]
3637
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
37-
#[rustc_allocator_nounwind]
38+
#[rustc_reallocator]
39+
#[rustc_nounwind]
3840
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
39-
#[rustc_allocator_nounwind]
41+
#[rustc_allocator_zeroed]
42+
#[rustc_nounwind]
4043
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
4144
}
4245

@@ -72,11 +75,14 @@ pub use std::alloc::Global;
7275
/// # Examples
7376
///
7477
/// ```
75-
/// use std::alloc::{alloc, dealloc, Layout};
78+
/// use std::alloc::{alloc, dealloc, handle_alloc_error, Layout};
7679
///
7780
/// unsafe {
7881
/// let layout = Layout::new::<u16>();
7982
/// let ptr = alloc(layout);
83+
/// if ptr.is_null() {
84+
/// handle_alloc_error(layout);
85+
/// }
8086
///
8187
/// *(ptr as *mut u16) = 42;
8288
/// assert_eq!(*(ptr as *mut u16), 42);
@@ -349,7 +355,7 @@ pub(crate) const unsafe fn box_free<T: ?Sized, A: ~const Allocator + ~const Dest
349355

350356
#[cfg(not(no_global_oom_handling))]
351357
extern "Rust" {
352-
// This is the magic symbol to call the global alloc error handler. rustc generates
358+
// This is the magic symbol to call the global alloc error handler. rustc generates
353359
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
354360
// default implementations below (`__rdl_oom`) otherwise.
355361
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
@@ -394,25 +400,24 @@ pub use std::alloc::handle_alloc_error;
394400
#[allow(unused_attributes)]
395401
#[unstable(feature = "alloc_internals", issue = "none")]
396402
pub mod __alloc_error_handler {
397-
use crate::alloc::Layout;
398-
399-
// called via generated `__rust_alloc_error_handler`
400-
401-
// if there is no `#[alloc_error_handler]`
403+
// called via generated `__rust_alloc_error_handler` if there is no
404+
// `#[alloc_error_handler]`.
402405
#[rustc_std_internal_symbol]
403-
pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! {
404-
panic!("memory allocation of {size} bytes failed")
405-
}
406-
407-
// if there is an `#[alloc_error_handler]`
408-
#[rustc_std_internal_symbol]
409-
pub unsafe extern "C-unwind" fn __rg_oom(size: usize, align: usize) -> ! {
410-
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
406+
pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
411407
extern "Rust" {
412-
#[lang = "oom"]
413-
fn oom_impl(layout: Layout) -> !;
408+
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
409+
// Its value depends on the -Zoom={panic,abort} compiler option.
410+
static __rust_alloc_error_handler_should_panic: u8;
411+
}
412+
413+
#[allow(unused_unsafe)]
414+
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
415+
panic!("memory allocation of {size} bytes failed")
416+
} else {
417+
core::panicking::panic_nounwind_fmt(format_args!(
418+
"memory allocation of {size} bytes failed"
419+
))
414420
}
415-
unsafe { oom_impl(layout) }
416421
}
417422
}
418423

0 commit comments

Comments
 (0)