From 5211f0f799b84b662f0ad9bea987e55b3d0a3dff Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 29 Jul 2023 19:37:59 +0200 Subject: [PATCH 1/5] rust: kernel: fix `unused_mut` warnings Signed-off-by: Miguel Ojeda --- rust/kernel/chrdev.rs | 2 +- rust/kernel/fs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/chrdev.rs b/rust/kernel/chrdev.rs index 5b1e083c23b909..71adb105b45db5 100644 --- a/rust/kernel/chrdev.rs +++ b/rust/kernel/chrdev.rs @@ -160,7 +160,7 @@ impl Registration<{ N }> { }); } - let mut inner = this.inner.as_mut().unwrap(); + let inner = this.inner.as_mut().unwrap(); if inner.used == N { return Err(EINVAL); } diff --git a/rust/kernel/fs.rs b/rust/kernel/fs.rs index 1ba01629e9cda2..8c0f61da3e3939 100644 --- a/rust/kernel/fs.rs +++ b/rust/kernel/fs.rs @@ -428,7 +428,7 @@ impl Registration { return Err(EINVAL); } - let mut fs = this.fs.get_mut(); + let fs = this.fs.get_mut(); fs.owner = module.0; fs.name = T::NAME.as_char_ptr(); fs.fs_flags = T::FLAGS; From 6abe8c9688d6033f1d5cde1c0468e363602a7a1e Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Mon, 24 Jul 2023 12:04:42 +0200 Subject: [PATCH 2/5] rust: upgrade to Rust 1.71.0 Upgrade the Rust toolchain from 1.70.0 to 1.71.0, to match the upcoming upgrade to mainline and thus reduce the differences. Signed-off-by: Miguel Ojeda --- Documentation/process/changes.rst | 2 +- rust/Makefile | 4 +- rust/alloc/alloc.rs | 12 +++++- rust/alloc/borrow.rs | 8 ++-- rust/alloc/boxed.rs | 72 ++++++++++++++++++------------- rust/alloc/boxed/thin.rs | 10 ++--- rust/alloc/fmt.rs | 10 ++--- rust/alloc/lib.rs | 6 +-- rust/alloc/str.rs | 6 +-- rust/alloc/string.rs | 27 +++++++++--- rust/alloc/vec/drain.rs | 8 ++-- rust/alloc/vec/drain_filter.rs | 8 ++-- rust/alloc/vec/mod.rs | 28 ++++++------ rust/compiler_builtins.rs | 7 +++ rust/kernel/allocator.rs | 41 +----------------- rust/kernel/driver.rs | 2 +- scripts/min-tool-version.sh | 2 +- 17 files changed, 124 insertions(+), 129 deletions(-) diff --git a/Documentation/process/changes.rst b/Documentation/process/changes.rst index 849b36f2069ba0..01209d652e601d 100644 --- a/Documentation/process/changes.rst +++ b/Documentation/process/changes.rst @@ -31,7 +31,7 @@ you probably needn't concern yourself with pcmciautils. ====================== =============== ======================================== GNU C 5.1 gcc --version Clang/LLVM (optional) 11.0.0 clang --version -Rust (optional) 1.70.0 rustc --version +Rust (optional) 1.71.0 rustc --version bindgen (optional) 0.56.0 bindgen --version GNU make 3.82 make --version bash 4.2 bash --version diff --git a/rust/Makefile b/rust/Makefile index e27f5d90843688..ce472b2113c851 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -396,8 +396,8 @@ rust-analyzer: $(RUST_LIB_SRC) > $(objtree)/rust-project.json redirect-intrinsics = \ - __eqsf2 __gesf2 __lesf2 __nesf2 __unordsf2 \ - __unorddf2 \ + __addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __unordsf2 \ + __adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \ __muloti4 __multi3 \ __udivmodti4 __udivti3 __umodti3 \ __aeabi_fcmpeq __aeabi_fcmpun __aeabi_dcmpun __aeabi_uldivmod diff --git a/rust/alloc/alloc.rs b/rust/alloc/alloc.rs index 5b2517225fc9f5..0b6bf5b6da4345 100644 --- a/rust/alloc/alloc.rs +++ b/rust/alloc/alloc.rs @@ -39,6 +39,9 @@ extern "Rust" { #[rustc_allocator_zeroed] #[rustc_nounwind] fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8; + + #[cfg(not(bootstrap))] + static __rust_no_alloc_shim_is_unstable: u8; } /// The global memory allocator. @@ -92,7 +95,14 @@ pub use std::alloc::Global; #[must_use = "losing the pointer will leak memory"] #[inline] pub unsafe fn alloc(layout: Layout) -> *mut u8 { - unsafe { __rust_alloc(layout.size(), layout.align()) } + unsafe { + // Make sure we don't accidentally allow omitting the allocator shim in + // stable code until it is actually stabilized. + #[cfg(not(bootstrap))] + core::ptr::read_volatile(&__rust_no_alloc_shim_is_unstable); + + __rust_alloc(layout.size(), layout.align()) + } } /// Deallocate memory with the global allocator. diff --git a/rust/alloc/borrow.rs b/rust/alloc/borrow.rs index bdf29cf790827a..68de15fd229dcd 100644 --- a/rust/alloc/borrow.rs +++ b/rust/alloc/borrow.rs @@ -117,7 +117,7 @@ where /// ``` /// use std::borrow::Cow; /// -/// fn abs_all(input: &mut Cow<[i32]>) { +/// fn abs_all(input: &mut Cow<'_, [i32]>) { /// for i in 0..input.len() { /// let v = input[i]; /// if v < 0 { @@ -147,7 +147,7 @@ where /// ``` /// use std::borrow::Cow; /// -/// struct Items<'a, X: 'a> where [X]: ToOwned> { +/// struct Items<'a, X> where [X]: ToOwned> { /// values: Cow<'a, [X]>, /// } /// @@ -269,7 +269,7 @@ impl Cow<'_, B> { /// /// assert_eq!( /// cow, - /// Cow::Owned(String::from("FOO")) as Cow + /// Cow::Owned(String::from("FOO")) as Cow<'_, str> /// ); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -313,7 +313,7 @@ impl Cow<'_, B> { /// use std::borrow::Cow; /// /// let s = "Hello world!"; - /// let cow: Cow = Cow::Owned(String::from(s)); + /// let cow: Cow<'_, str> = Cow::Owned(String::from(s)); /// /// assert_eq!( /// cow.into_owned(), diff --git a/rust/alloc/boxed.rs b/rust/alloc/boxed.rs index 0186dab33a3748..7725a968ce01d8 100644 --- a/rust/alloc/boxed.rs +++ b/rust/alloc/boxed.rs @@ -578,8 +578,7 @@ impl Box { /// /// This conversion does not allocate on the heap and happens in place. #[unstable(feature = "box_into_boxed_slice", issue = "71582")] - #[rustc_const_unstable(feature = "const_box", issue = "92521")] - pub const fn into_boxed_slice(boxed: Self) -> Box<[T], A> { + pub fn into_boxed_slice(boxed: Self) -> Box<[T], A> { let (raw, alloc) = Box::into_raw_with_allocator(boxed); unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) } } @@ -811,9 +810,8 @@ impl Box, A> { /// assert_eq!(*five, 5) /// ``` #[unstable(feature = "new_uninit", issue = "63291")] - #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[inline] - pub const unsafe fn assume_init(self) -> Box { + pub unsafe fn assume_init(self) -> Box { let (raw, alloc) = Box::into_raw_with_allocator(self); unsafe { Box::from_raw_in(raw as *mut T, alloc) } } @@ -846,9 +844,8 @@ impl Box, A> { /// } /// ``` #[unstable(feature = "new_uninit", issue = "63291")] - #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[inline] - pub const fn write(mut boxed: Self, value: T) -> Box { + pub fn write(mut boxed: Self, value: T) -> Box { unsafe { (*boxed).write(value); boxed.assume_init() @@ -1092,9 +1089,8 @@ impl Box { /// /// [memory layout]: self#memory-layout #[unstable(feature = "allocator_api", issue = "32838")] - #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[inline] - pub const fn into_raw_with_allocator(b: Self) -> (*mut T, A) { + pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) { let (leaked, alloc) = Box::into_unique(b); (leaked.as_ptr(), alloc) } @@ -1104,10 +1100,9 @@ impl Box { issue = "none", reason = "use `Box::leak(b).into()` or `Unique::from(Box::leak(b))` instead" )] - #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[inline] #[doc(hidden)] - pub const fn into_unique(b: Self) -> (Unique, A) { + pub fn into_unique(b: Self) -> (Unique, A) { // Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a // raw pointer for the type system. Turning it directly into a raw pointer would not be // recognized as "releasing" the unique pointer to permit aliased raw accesses, @@ -1165,9 +1160,8 @@ impl Box { /// assert_eq!(*static_ref, [4, 2, 3]); /// ``` #[stable(feature = "box_leak", since = "1.26.0")] - #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[inline] - pub const fn leak<'a>(b: Self) -> &'a mut T + pub fn leak<'a>(b: Self) -> &'a mut T where A: 'a, { @@ -1236,8 +1230,7 @@ impl Default for Box { #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] -impl const Default for Box<[T]> { +impl Default for Box<[T]> { #[inline] fn default() -> Self { let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling(); @@ -1247,8 +1240,7 @@ impl const Default for Box<[T]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "default_box_extra", since = "1.17.0")] -#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] -impl const Default for Box { +impl Default for Box { #[inline] fn default() -> Self { // SAFETY: This is the same as `Unique::cast` but with an unsized `U = str`. @@ -1445,8 +1437,7 @@ impl From for Box { } #[stable(feature = "pin", since = "1.33.0")] -#[rustc_const_unstable(feature = "const_box", issue = "92521")] -impl const From> for Pin> +impl From> for Pin> where A: 'static, { @@ -1466,9 +1457,36 @@ where } } +/// Specialization trait used for `From<&[T]>`. +#[cfg(not(no_global_oom_handling))] +trait BoxFromSlice { + fn from_slice(slice: &[T]) -> Self; +} + +#[cfg(not(no_global_oom_handling))] +impl BoxFromSlice for Box<[T]> { + #[inline] + default fn from_slice(slice: &[T]) -> Self { + slice.to_vec().into_boxed_slice() + } +} + +#[cfg(not(no_global_oom_handling))] +impl BoxFromSlice for Box<[T]> { + #[inline] + fn from_slice(slice: &[T]) -> Self { + let len = slice.len(); + let buf = RawVec::with_capacity(len); + unsafe { + ptr::copy_nonoverlapping(slice.as_ptr(), buf.ptr(), len); + buf.into_box(slice.len()).assume_init() + } + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "box_from_slice", since = "1.17.0")] -impl From<&[T]> for Box<[T]> { +impl From<&[T]> for Box<[T]> { /// Converts a `&[T]` into a `Box<[T]>` /// /// This conversion allocates on the heap @@ -1482,19 +1500,15 @@ impl From<&[T]> for Box<[T]> { /// /// println!("{boxed_slice:?}"); /// ``` + #[inline] fn from(slice: &[T]) -> Box<[T]> { - let len = slice.len(); - let buf = RawVec::with_capacity(len); - unsafe { - ptr::copy_nonoverlapping(slice.as_ptr(), buf.ptr(), len); - buf.into_box(slice.len()).assume_init() - } + >::from_slice(slice) } } #[cfg(not(no_global_oom_handling))] #[stable(feature = "box_from_cow", since = "1.45.0")] -impl From> for Box<[T]> { +impl From> for Box<[T]> { /// Converts a `Cow<'_, [T]>` into a `Box<[T]>` /// /// When `cow` is the `Cow::Borrowed` variant, this @@ -1882,8 +1896,7 @@ impl fmt::Pointer for Box { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_box", issue = "92521")] -impl const Deref for Box { +impl Deref for Box { type Target = T; fn deref(&self) -> &T { @@ -1892,8 +1905,7 @@ impl const Deref for Box { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_box", issue = "92521")] -impl const DerefMut for Box { +impl DerefMut for Box { fn deref_mut(&mut self) -> &mut T { &mut **self } diff --git a/rust/alloc/boxed/thin.rs b/rust/alloc/boxed/thin.rs index 3aebf3ea94525e..25ee9c0d78f17d 100644 --- a/rust/alloc/boxed/thin.rs +++ b/rust/alloc/boxed/thin.rs @@ -9,7 +9,7 @@ use core::fmt::{self, Debug, Display, Formatter}; use core::marker::PhantomData; #[cfg(not(no_global_oom_handling))] use core::marker::Unsize; -use core::mem; +use core::mem::{self, SizedTypeProperties}; use core::ops::{Deref, DerefMut}; use core::ptr::Pointee; use core::ptr::{self, NonNull}; @@ -204,9 +204,7 @@ impl WithHeader { let ptr = if layout.size() == 0 { // Some paranoia checking, mostly so that the ThinBox tests are // more able to catch issues. - debug_assert!( - value_offset == 0 && mem::size_of::() == 0 && mem::size_of::() == 0 - ); + debug_assert!(value_offset == 0 && T::IS_ZST && H::IS_ZST); layout.dangling() } else { let ptr = alloc::alloc(layout); @@ -251,9 +249,7 @@ impl WithHeader { alloc::dealloc(self.ptr.as_ptr().sub(value_offset), layout); } else { debug_assert!( - value_offset == 0 - && mem::size_of::() == 0 - && self.value_layout.size() == 0 + value_offset == 0 && H::IS_ZST && self.value_layout.size() == 0 ); } } diff --git a/rust/alloc/fmt.rs b/rust/alloc/fmt.rs index 4594140df595b1..8dba3ec6e69431 100644 --- a/rust/alloc/fmt.rs +++ b/rust/alloc/fmt.rs @@ -365,7 +365,7 @@ //! # use std::fmt; //! # struct Foo; // our custom type //! # impl fmt::Display for Foo { -//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { //! # write!(f, "testing, testing") //! # } } //! ``` @@ -401,7 +401,7 @@ //! } //! //! impl fmt::Display for Vector2D { -//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { //! // The `f` value implements the `Write` trait, which is what the //! // write! macro is expecting. Note that this formatting ignores the //! // various flags provided to format strings. @@ -412,7 +412,7 @@ //! // Different traits allow different forms of output of a type. The meaning //! // of this format is to print the magnitude of a vector. //! impl fmt::Binary for Vector2D { -//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { //! let magnitude = (self.x * self.x + self.y * self.y) as f64; //! let magnitude = magnitude.sqrt(); //! @@ -519,7 +519,7 @@ //! let mut some_writer = io::stdout(); //! write!(&mut some_writer, "{}", format_args!("print with a {}", "macro")); //! -//! fn my_fmt_fn(args: fmt::Arguments) { +//! fn my_fmt_fn(args: fmt::Arguments<'_>) { //! write!(&mut io::stdout(), "{args}"); //! } //! my_fmt_fn(format_args!(", or a {} too", "function")); @@ -553,8 +553,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -#[unstable(feature = "fmt_internals", issue = "none")] -pub use core::fmt::rt; #[stable(feature = "fmt_flags_align", since = "1.28.0")] pub use core::fmt::Alignment; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/rust/alloc/lib.rs b/rust/alloc/lib.rs index 2f462a5216cfa0..76a1a941b3a38d 100644 --- a/rust/alloc/lib.rs +++ b/rust/alloc/lib.rs @@ -103,19 +103,18 @@ #![feature(array_into_iter_constructors)] #![feature(array_methods)] #![feature(array_windows)] +#![feature(ascii_char)] #![feature(assert_matches)] #![feature(async_iterator)] #![feature(coerce_unsized)] #![feature(const_align_of_val)] #![feature(const_box)] -#![feature(const_convert)] -#![feature(const_cow_is_borrowed)] +#![cfg_attr(not(no_borrow), feature(const_cow_is_borrowed))] #![feature(const_eval_select)] #![feature(const_maybe_uninit_as_mut_ptr)] #![feature(const_maybe_uninit_write)] #![feature(const_maybe_uninit_zeroed)] #![feature(const_pin)] -#![feature(const_ptr_read)] #![feature(const_refs_to_cell)] #![feature(const_size_of_val)] #![feature(const_waker)] @@ -176,7 +175,6 @@ #![feature(associated_type_bounds)] #![feature(c_unwind)] #![feature(cfg_sanitize)] -#![feature(const_deref)] #![feature(const_mut_refs)] #![feature(const_precise_live_drops)] #![feature(const_ptr_write)] diff --git a/rust/alloc/str.rs b/rust/alloc/str.rs index d33ece5fc64c07..3aa73cf12f6584 100644 --- a/rust/alloc/str.rs +++ b/rust/alloc/str.rs @@ -406,12 +406,12 @@ impl str { // See https://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992 // for the definition of `Final_Sigma`. debug_assert!('Σ'.len_utf8() == 2); - let is_word_final = case_ignoreable_then_cased(from[..i].chars().rev()) - && !case_ignoreable_then_cased(from[i + 2..].chars()); + let is_word_final = case_ignorable_then_cased(from[..i].chars().rev()) + && !case_ignorable_then_cased(from[i + 2..].chars()); to.push_str(if is_word_final { "ς" } else { "σ" }); } - fn case_ignoreable_then_cased>(iter: I) -> bool { + fn case_ignorable_then_cased>(iter: I) -> bool { use core::unicode::{Case_Ignorable, Cased}; match iter.skip_while(|&c| Case_Ignorable(c)).next() { Some(c) => Cased(c), diff --git a/rust/alloc/string.rs b/rust/alloc/string.rs index 5290a0cd62b3a0..fe5e580fdb7daa 100644 --- a/rust/alloc/string.rs +++ b/rust/alloc/string.rs @@ -1853,7 +1853,7 @@ impl String { } /// Consumes and leaks the `String`, returning a mutable reference to the contents, - /// `&'static mut str`. + /// `&'a mut str`. /// /// This is mainly useful for data that lives for the remainder of /// the program's life. Dropping the returned reference will cause a memory @@ -1876,7 +1876,7 @@ impl String { /// ``` #[unstable(feature = "string_leak", issue = "102929")] #[inline] - pub fn leak(self) -> &'static mut str { + pub fn leak<'a>(self) -> &'a mut str { let slice = self.vec.leak(); unsafe { from_utf8_unchecked_mut(slice) } } @@ -2249,8 +2249,7 @@ impl_eq! { Cow<'a, str>, &'b str } impl_eq! { Cow<'a, str>, String } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] -impl const Default for String { +impl Default for String { /// Creates an empty `String`. #[inline] fn default() -> String { @@ -2529,6 +2528,15 @@ impl ToString for T { } } +#[cfg(not(no_global_oom_handling))] +#[unstable(feature = "ascii_char", issue = "110998")] +impl ToString for core::ascii::Char { + #[inline] + fn to_string(&self) -> String { + self.as_str().to_owned() + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "char_to_string_specialization", since = "1.46.0")] impl ToString for char { @@ -2617,6 +2625,15 @@ impl ToString for String { } } +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "fmt_arguments_to_string_specialization", since = "1.71.0")] +impl ToString for fmt::Arguments<'_> { + #[inline] + fn to_string(&self) -> String { + crate::fmt::format(*self) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl AsRef for String { #[inline] @@ -2735,7 +2752,7 @@ impl<'a> From> for String { /// ``` /// # use std::borrow::Cow; /// // If the string is not owned... - /// let cow: Cow = Cow::Borrowed("eggplant"); + /// let cow: Cow<'_, str> = Cow::Borrowed("eggplant"); /// // It will allocate on the heap and copy the string. /// let owned: String = String::from(cow); /// assert_eq!(&owned[..], "eggplant"); diff --git a/rust/alloc/vec/drain.rs b/rust/alloc/vec/drain.rs index d503d2f478ce7a..78177a9e2ad0c2 100644 --- a/rust/alloc/vec/drain.rs +++ b/rust/alloc/vec/drain.rs @@ -18,7 +18,7 @@ use super::Vec; /// /// ``` /// let mut v = vec![0, 1, 2]; -/// let iter: std::vec::Drain<_> = v.drain(..); +/// let iter: std::vec::Drain<'_, _> = v.drain(..); /// ``` #[stable(feature = "drain", since = "1.6.0")] pub struct Drain< @@ -114,9 +114,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> { let unyielded_ptr = this.iter.as_slice().as_ptr(); // ZSTs have no identity, so we don't need to move them around. - let needs_move = mem::size_of::() != 0; - - if needs_move { + if !T::IS_ZST { let start_ptr = source_vec.as_mut_ptr().add(start); // memmove back unyielded elements @@ -199,7 +197,7 @@ impl Drop for Drain<'_, T, A> { } } - let iter = mem::replace(&mut self.iter, (&mut []).iter()); + let iter = mem::take(&mut self.iter); let drop_len = iter.len(); let mut vec = self.vec; diff --git a/rust/alloc/vec/drain_filter.rs b/rust/alloc/vec/drain_filter.rs index 4b019220657dfc..09efff090e428c 100644 --- a/rust/alloc/vec/drain_filter.rs +++ b/rust/alloc/vec/drain_filter.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use crate::alloc::{Allocator, Global}; -use core::mem::{self, ManuallyDrop}; +use core::mem::{ManuallyDrop, SizedTypeProperties}; use core::ptr; use core::slice; @@ -18,7 +18,7 @@ use super::Vec; /// #![feature(drain_filter)] /// /// let mut v = vec![0, 1, 2]; -/// let iter: std::vec::DrainFilter<_, _> = v.drain_filter(|x| *x % 2 == 0); +/// let iter: std::vec::DrainFilter<'_, _, _> = v.drain_filter(|x| *x % 2 == 0); /// ``` #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] #[derive(Debug)] @@ -98,9 +98,7 @@ where unsafe { // ZSTs have no identity, so we don't need to move them around. - let needs_move = mem::size_of::() != 0; - - if needs_move && this.idx < this.old_len && this.del > 0 { + if !T::IS_ZST && this.idx < this.old_len && this.del > 0 { let ptr = this.vec.as_mut_ptr(); let src = ptr.add(this.idx); let dst = src.sub(this.del); diff --git a/rust/alloc/vec/mod.rs b/rust/alloc/vec/mod.rs index 38f5ee24e73002..63c23beed2b7a2 100644 --- a/rust/alloc/vec/mod.rs +++ b/rust/alloc/vec/mod.rs @@ -702,14 +702,14 @@ impl Vec { /// /// // The vector contains no items, even though it has capacity for more /// assert_eq!(vec.len(), 0); - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// /// // These are all done without reallocating... /// for i in 0..10 { /// vec.push(i); /// } /// assert_eq!(vec.len(), 10); - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// /// // ...but this may make the vector reallocate /// vec.push(11); @@ -760,14 +760,14 @@ impl Vec { /// /// // The vector contains no items, even though it has capacity for more /// assert_eq!(vec.len(), 0); - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// /// // These are all done without reallocating... /// for i in 0..10 { /// vec.push(i); /// } /// assert_eq!(vec.len(), 10); - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// /// // ...but this may make the vector reallocate /// vec.push(11); @@ -993,7 +993,7 @@ impl Vec { /// ``` /// let mut vec: Vec = Vec::with_capacity(10); /// vec.push(42); - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -1144,7 +1144,7 @@ impl Vec { /// ``` /// let mut vec = Vec::with_capacity(10); /// vec.extend([1, 2, 3]); - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// vec.shrink_to_fit(); /// assert!(vec.capacity() >= 3); /// ``` @@ -1169,7 +1169,7 @@ impl Vec { /// ``` /// let mut vec = Vec::with_capacity(10); /// vec.extend([1, 2, 3]); - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// vec.try_shrink_to_fit().unwrap(); /// assert!(vec.capacity() >= 3); /// ``` @@ -1197,7 +1197,7 @@ impl Vec { /// ``` /// let mut vec = Vec::with_capacity(10); /// vec.extend([1, 2, 3]); - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// vec.shrink_to(4); /// assert!(vec.capacity() >= 4); /// vec.shrink_to(0); @@ -1232,7 +1232,7 @@ impl Vec { /// let mut vec = Vec::with_capacity(10); /// vec.extend([1, 2, 3]); /// - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// let slice = vec.into_boxed_slice(); /// assert_eq!(slice.into_vec().capacity(), 3); /// ``` @@ -1269,7 +1269,7 @@ impl Vec { /// let mut vec = Vec::with_capacity(10); /// vec.extend([1, 2, 3]); /// - /// assert_eq!(vec.capacity(), 10); + /// assert!(vec.capacity() >= 10); /// let slice = vec.try_into_boxed_slice().unwrap(); /// assert_eq!(slice.into_vec().capacity(), 3); /// ``` @@ -2967,7 +2967,6 @@ impl Clone for Vec { /// as required by the `core::borrow::Borrow` implementation. /// /// ``` -/// #![feature(build_hasher_simple_hash_one)] /// use std::hash::BuildHasher; /// /// let b = std::collections::hash_map::RandomState::new(); @@ -3384,8 +3383,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] -impl const Default for Vec { +impl Default for Vec { /// Creates an empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -3505,8 +3503,8 @@ where /// /// ``` /// # use std::borrow::Cow; - /// let o: Cow<[i32]> = Cow::Owned(vec![1, 2, 3]); - /// let b: Cow<[i32]> = Cow::Borrowed(&[1, 2, 3]); + /// let o: Cow<'_, [i32]> = Cow::Owned(vec![1, 2, 3]); + /// let b: Cow<'_, [i32]> = Cow::Borrowed(&[1, 2, 3]); /// assert_eq!(Vec::from(o), Vec::from(b)); /// ``` fn from(s: Cow<'a, [T]>) -> Vec { diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs index 565a583db7ad75..fd2fcaeca0b43d 100644 --- a/rust/compiler_builtins.rs +++ b/rust/compiler_builtins.rs @@ -37,14 +37,21 @@ macro_rules! define_panicking_intrinsics( ); define_panicking_intrinsics!("`f32` should not be used", { + __addsf3, __eqsf2, __gesf2, __lesf2, + __ltsf2, + __mulsf3, __nesf2, __unordsf2, }); define_panicking_intrinsics!("`f64` should not be used", { + __adddf3, + __ledf2, + __ltdf2, + __muldf3, __unorddf2, }); diff --git a/rust/kernel/allocator.rs b/rust/kernel/allocator.rs index 280676993074c1..cfb406e2a7102a 100644 --- a/rust/kernel/allocator.rs +++ b/rust/kernel/allocator.rs @@ -26,43 +26,6 @@ unsafe impl GlobalAlloc for KernelAllocator { #[global_allocator] static ALLOCATOR: KernelAllocator = KernelAllocator; -// `rustc` only generates these for some crate types. Even then, we would need -// to extract the object file that has them from the archive. For the moment, -// let's generate them ourselves instead. -// -// Note that `#[no_mangle]` implies exported too, nowadays. -#[allow(clippy::no_mangle_with_rust_abi)] +// See . #[no_mangle] -fn __rust_alloc(size: usize, _align: usize) -> *mut u8 { - unsafe { bindings::krealloc(core::ptr::null(), size, bindings::GFP_KERNEL) as *mut u8 } -} - -#[allow(clippy::no_mangle_with_rust_abi)] -#[no_mangle] -fn __rust_dealloc(ptr: *mut u8, _size: usize, _align: usize) { - unsafe { bindings::kfree(ptr as *const core::ffi::c_void) }; -} - -#[allow(clippy::no_mangle_with_rust_abi)] -#[no_mangle] -fn __rust_realloc(ptr: *mut u8, _old_size: usize, _align: usize, new_size: usize) -> *mut u8 { - unsafe { - bindings::krealloc( - ptr as *const core::ffi::c_void, - new_size, - bindings::GFP_KERNEL, - ) as *mut u8 - } -} - -#[allow(clippy::no_mangle_with_rust_abi)] -#[no_mangle] -fn __rust_alloc_zeroed(size: usize, _align: usize) -> *mut u8 { - unsafe { - bindings::krealloc( - core::ptr::null(), - size, - bindings::GFP_KERNEL | bindings::__GFP_ZERO, - ) as *mut u8 - } -} +static __rust_no_alloc_shim_is_unstable: u8 = 0; diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index af42a773256e05..d8f5f62022f758 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -196,7 +196,7 @@ pub struct IdTable<'a, T: RawDeviceId, U> { _p: PhantomData<&'a U>, } -impl const AsRef for IdTable<'_, T, U> { +impl AsRef for IdTable<'_, T, U> { fn as_ref(&self) -> &T::RawType { self.first } diff --git a/scripts/min-tool-version.sh b/scripts/min-tool-version.sh index c55875107673c2..ffcd3941859d41 100755 --- a/scripts/min-tool-version.sh +++ b/scripts/min-tool-version.sh @@ -27,7 +27,7 @@ llvm) fi ;; rustc) - echo 1.70.0 + echo 1.71.0 ;; bindgen) echo 0.56.0 From a69bfd2f39922870cfd14e7ff4c2f3e971d1455e Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 29 Jul 2023 20:30:32 +0200 Subject: [PATCH 3/5] rust: compiler_builtins: `__subsf3` for ppc64le powerpc64le-linux-gnu-ld: rust/core.o: in function `::neg': core.bd923ab8a410e564-cgu.0:(.text+0x2a5b8): undefined reference to `__subsf3' Signed-off-by: Miguel Ojeda --- rust/Makefile | 2 +- rust/compiler_builtins.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/Makefile b/rust/Makefile index ce472b2113c851..748b21a5f6cb56 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -396,7 +396,7 @@ rust-analyzer: $(RUST_LIB_SRC) > $(objtree)/rust-project.json redirect-intrinsics = \ - __addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __unordsf2 \ + __addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __subsf3 __unordsf2 \ __adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \ __muloti4 __multi3 \ __udivmodti4 __udivti3 __umodti3 \ diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs index fd2fcaeca0b43d..779c3266aba177 100644 --- a/rust/compiler_builtins.rs +++ b/rust/compiler_builtins.rs @@ -44,6 +44,7 @@ define_panicking_intrinsics!("`f32` should not be used", { __ltsf2, __mulsf3, __nesf2, + __subsf3, __unordsf2, }); From b8476c9901df668b485a204a644f73e83a316822 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 29 Jul 2023 23:25:11 +0200 Subject: [PATCH 4/5] rust: compiler_builtins: more for `arm` due to `midpoint` e.g. >>> referenced by f32.rs:964 (/root/.rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/f32.rs:964) >>> rust/core.o:(::midpoint) in archive vmlinux.a >>> referenced by f32.rs:964 (/root/.rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/f32.rs:964) >>> rust/core.o:(::midpoint) in archive vmlinux.a Signed-off-by: Miguel Ojeda --- rust/Makefile | 4 +++- rust/compiler_builtins.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/rust/Makefile b/rust/Makefile index 748b21a5f6cb56..c71b89a2a60624 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -400,7 +400,9 @@ redirect-intrinsics = \ __adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \ __muloti4 __multi3 \ __udivmodti4 __udivti3 __umodti3 \ - __aeabi_fcmpeq __aeabi_fcmpun __aeabi_dcmpun __aeabi_uldivmod + __aeabi_fadd __aeabi_fmul __aeabi_fcmpeq __aeabi_fcmple __aeabi_fcmplt __aeabi_fcmpun \ + __aeabi_dadd __aeabi_dmul __aeabi_dcmple __aeabi_dcmplt __aeabi_dcmpun \ + __aeabi_uldivmod ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) # These intrinsics are defined for ARM64 and RISCV64 diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs index 779c3266aba177..3255833d0b560d 100644 --- a/rust/compiler_builtins.rs +++ b/rust/compiler_builtins.rs @@ -72,12 +72,20 @@ define_panicking_intrinsics!("`u128` should not be used", { #[cfg(target_arch = "arm")] define_panicking_intrinsics!("`f32` should not be used", { + __aeabi_fadd, + __aeabi_fmul, __aeabi_fcmpeq, + __aeabi_fcmple, + __aeabi_fcmplt, __aeabi_fcmpun, }); #[cfg(target_arch = "arm")] define_panicking_intrinsics!("`f64` should not be used", { + __aeabi_dadd, + __aeabi_dmul, + __aeabi_dcmple, + __aeabi_dcmplt, __aeabi_dcmpun, }); From 492857088c1984e400d84be6462ac84aea6e4f3b Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 29 Jul 2023 20:25:16 +0200 Subject: [PATCH 5/5] CI: upgrade to Rust 1.71.0 Signed-off-by: Miguel Ojeda --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d0ae127ed8ced5..d35699790a2efd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,7 +7,7 @@ on: jobs: ci: runs-on: ubuntu-20.04 - container: ghcr.io/rust-for-linux/ci:Rust-1.70.0 + container: ghcr.io/rust-for-linux/ci:Rust-1.71.0 timeout-minutes: 25 strategy: