From e90ab6fad28eb28db5bc69426414704862f8c720 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Thu, 19 May 2022 21:32:42 +0200 Subject: [PATCH] Rust 1.61.0 Signed-off-by: Miguel Ojeda --- .github/workflows/ci.yaml | 2 +- Documentation/process/changes.rst | 2 +- rust/alloc/alloc.rs | 10 ++++++-- rust/alloc/borrow.rs | 3 ++- rust/alloc/boxed.rs | 40 ++++++++++++++++++------------- rust/alloc/fmt.rs | 6 ++--- rust/alloc/lib.rs | 4 ++-- rust/alloc/raw_vec.rs | 9 ++++--- rust/alloc/slice.rs | 25 +++++++++++++++---- rust/alloc/str.rs | 12 +++++++++- rust/alloc/string.rs | 4 ++-- rust/alloc/vec/into_iter.rs | 35 +++++++++++++++------------ rust/alloc/vec/mod.rs | 40 ++++++++++++++++--------------- rust/alloc/vec/partial_eq.rs | 2 +- rust/kernel/lib.rs | 1 - scripts/min-tool-version.sh | 2 +- 16 files changed, 121 insertions(+), 76 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b3324796d34a76..e43b1cc7201fdf 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.60.0 + container: ghcr.io/rust-for-linux/ci:Rust-1.61.0 timeout-minutes: 20 strategy: diff --git a/Documentation/process/changes.rst b/Documentation/process/changes.rst index a886ac497266b5..331229b13c099c 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.60.0 rustc --version +Rust (optional) 1.61.0 rustc --version bindgen (optional) 0.56.0 bindgen --version GNU make 3.81 make --version binutils 2.23 ld -v diff --git a/rust/alloc/alloc.rs b/rust/alloc/alloc.rs index cea3b747673fd6..dbddc6787c4737 100644 --- a/rust/alloc/alloc.rs +++ b/rust/alloc/alloc.rs @@ -16,6 +16,8 @@ use core::ptr::{self, NonNull}; #[doc(inline)] pub use core::alloc::*; +use core::marker::Destruct; + #[cfg(test)] mod tests; @@ -326,12 +328,16 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { #[cfg_attr(not(test), lang = "box_free")] #[inline] #[rustc_const_unstable(feature = "const_box", issue = "92521")] +#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping // This signature has to be the same as `Box`, otherwise an ICE will happen. // When an additional parameter to `Box` is added (like `A: Allocator`), this has to be added here as // well. // For example if `Box` is changed to `struct Box(Unique, A)`, // this function has to be changed to `fn box_free(Unique, A)` as well. -pub(crate) const unsafe fn box_free( +pub(crate) const unsafe fn box_free< + T: ?Sized, + A: ~const Allocator + ~const Drop + ~const Destruct, +>( ptr: Unique, alloc: A, ) { @@ -399,7 +405,7 @@ pub mod __alloc_error_handler { // if there is no `#[alloc_error_handler]` #[rustc_std_internal_symbol] pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! { - panic!("memory allocation of {} bytes failed", size) + panic!("memory allocation of {size} bytes failed") } // if there is an `#[alloc_error_handler]` diff --git a/rust/alloc/borrow.rs b/rust/alloc/borrow.rs index 8e1d8a76464136..bef5b2078ab440 100644 --- a/rust/alloc/borrow.rs +++ b/rust/alloc/borrow.rs @@ -163,7 +163,7 @@ where /// let readonly = [1, 2]; /// let borrowed = Items::new((&readonly[..]).into()); /// match borrowed { -/// Items { values: Cow::Borrowed(b) } => println!("borrowed {:?}", b), +/// Items { values: Cow::Borrowed(b) } => println!("borrowed {b:?}"), /// _ => panic!("expect borrowed value"), /// } /// @@ -333,6 +333,7 @@ impl Cow<'_, B> { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping impl const Deref for Cow<'_, B> where B::Owned: ~const Borrow, diff --git a/rust/alloc/boxed.rs b/rust/alloc/boxed.rs index 921fcef75e4b9b..78dc5a31a73d64 100644 --- a/rust/alloc/boxed.rs +++ b/rust/alloc/boxed.rs @@ -33,7 +33,7 @@ //! } //! //! let list: List = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Nil)))); -//! println!("{:?}", list); +//! println!("{list:?}"); //! ``` //! //! This will print `Cons(1, Cons(2, Nil))`. @@ -145,7 +145,7 @@ use core::hash::{Hash, Hasher}; #[cfg(not(no_global_oom_handling))] use core::iter::FromIterator; use core::iter::{FusedIterator, Iterator}; -use core::marker::{Unpin, Unsize}; +use core::marker::{Destruct, Unpin, Unsize}; use core::mem; use core::ops::{ CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver, @@ -351,9 +351,10 @@ impl Box { #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[must_use] #[inline] + #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping pub const fn new_in(x: T, alloc: A) -> Self where - A: ~const Allocator + ~const Drop, + A: ~const Allocator + ~const Drop + ~const Destruct, { let mut boxed = Self::new_uninit_in(alloc); unsafe { @@ -380,10 +381,11 @@ impl Box { #[unstable(feature = "allocator_api", issue = "32838")] #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[inline] + #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping pub const fn try_new_in(x: T, alloc: A) -> Result where - T: ~const Drop, - A: ~const Allocator + ~const Drop, + T: ~const Drop + ~const Destruct, + A: ~const Allocator + ~const Drop + ~const Destruct, { let mut boxed = Self::try_new_uninit_in(alloc)?; unsafe { @@ -417,9 +419,10 @@ impl Box { #[cfg(not(no_global_oom_handling))] #[must_use] // #[unstable(feature = "new_uninit", issue = "63291")] + #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping pub const fn new_uninit_in(alloc: A) -> Box, A> where - A: ~const Allocator + ~const Drop, + A: ~const Allocator + ~const Drop + ~const Destruct, { let layout = Layout::new::>(); // NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable. @@ -455,9 +458,10 @@ impl Box { #[unstable(feature = "allocator_api", issue = "32838")] // #[unstable(feature = "new_uninit", issue = "63291")] #[rustc_const_unstable(feature = "const_box", issue = "92521")] + #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping pub const fn try_new_uninit_in(alloc: A) -> Result, A>, AllocError> where - A: ~const Allocator + ~const Drop, + A: ~const Allocator + ~const Drop + ~const Destruct, { let layout = Layout::new::>(); let ptr = alloc.allocate(layout)?.cast(); @@ -489,9 +493,10 @@ impl Box { #[cfg(not(no_global_oom_handling))] // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] + #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping pub const fn new_zeroed_in(alloc: A) -> Box, A> where - A: ~const Allocator + ~const Drop, + A: ~const Allocator + ~const Drop + ~const Destruct, { let layout = Layout::new::>(); // NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable. @@ -527,9 +532,10 @@ impl Box { #[unstable(feature = "allocator_api", issue = "32838")] // #[unstable(feature = "new_uninit", issue = "63291")] #[rustc_const_unstable(feature = "const_box", issue = "92521")] + #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping pub const fn try_new_zeroed_in(alloc: A) -> Result, A>, AllocError> where - A: ~const Allocator + ~const Drop, + A: ~const Allocator + ~const Drop + ~const Destruct, { let layout = Layout::new::>(); let ptr = alloc.allocate_zeroed(layout)?.cast(); @@ -543,9 +549,10 @@ impl Box { #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[must_use] #[inline(always)] + #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping pub const fn pin_in(x: T, alloc: A) -> Pin where - A: 'static + ~const Allocator + ~const Drop, + A: 'static + ~const Allocator + ~const Drop + ~const Destruct, { Self::into_pin(Self::new_in(x, alloc)) } @@ -574,9 +581,10 @@ impl Box { #[unstable(feature = "box_into_inner", issue = "80437")] #[rustc_const_unstable(feature = "const_box", issue = "92521")] #[inline] + #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping pub const fn into_inner(boxed: Self) -> T where - Self: ~const Drop, + Self: ~const Drop + ~const Destruct, { *boxed } @@ -1409,7 +1417,7 @@ impl From<&[T]> for Box<[T]> { /// let slice: &[u8] = &[104, 101, 108, 108, 111]; /// let boxed_slice: Box<[u8]> = Box::from(slice); /// - /// println!("{:?}", boxed_slice); + /// println!("{boxed_slice:?}"); /// ``` fn from(slice: &[T]) -> Box<[T]> { let len = slice.len(); @@ -1451,7 +1459,7 @@ impl From<&str> for Box { /// /// ```rust /// let boxed: Box = Box::from("hello"); - /// println!("{}", boxed); + /// println!("{boxed}"); /// ``` #[inline] fn from(s: &str) -> Box { @@ -1476,14 +1484,14 @@ impl From> for Box { /// /// let unboxed = Cow::Borrowed("hello"); /// let boxed: Box = Box::from(unboxed); - /// println!("{}", boxed); + /// println!("{boxed}"); /// ``` /// /// ```rust /// # use std::borrow::Cow; /// let unboxed = Cow::Owned("hello".to_string()); /// let boxed: Box = Box::from(unboxed); - /// println!("{}", boxed); + /// println!("{boxed}"); /// ``` #[inline] fn from(cow: Cow<'_, str>) -> Box { @@ -1530,7 +1538,7 @@ impl From<[T; N]> for Box<[T]> { /// /// ```rust /// let boxed: Box<[u8]> = Box::from([4, 2]); - /// println!("{:?}", boxed); + /// println!("{boxed:?}"); /// ``` fn from(array: [T; N]) -> Box<[T]> { box array diff --git a/rust/alloc/fmt.rs b/rust/alloc/fmt.rs index be75e6637442e3..79ea0f68643e4c 100644 --- a/rust/alloc/fmt.rs +++ b/rust/alloc/fmt.rs @@ -418,9 +418,9 @@ //! fn main() { //! let myvector = Vector2D { x: 3, y: 4 }; //! -//! println!("{}", myvector); // => "(3, 4)" -//! println!("{:?}", myvector); // => "Vector2D {x: 3, y:4}" -//! println!("{:10.3b}", myvector); // => " 5.000" +//! println!("{myvector}"); // => "(3, 4)" +//! println!("{myvector:?}"); // => "Vector2D {x: 3, y:4}" +//! println!("{myvector:10.3b}"); // => " 5.000" //! } //! ``` //! diff --git a/rust/alloc/lib.rs b/rust/alloc/lib.rs index 085dc005170a05..8806850620837f 100644 --- a/rust/alloc/lib.rs +++ b/rust/alloc/lib.rs @@ -129,6 +129,7 @@ #![feature(slice_ptr_len)] #![feature(slice_range)] #![feature(str_internals)] +#![feature(strict_provenance)] #![feature(trusted_len)] #![feature(trusted_random_access)] #![feature(try_trait_v2)] @@ -141,9 +142,8 @@ #![feature(associated_type_bounds)] #![feature(box_syntax)] #![feature(cfg_sanitize)] -#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))] #![feature(const_deref)] -#![feature(const_fn_trait_bound)] +#![cfg_attr(bootstrap, feature(const_fn_trait_bound))] #![feature(const_mut_refs)] #![feature(const_ptr_write)] #![feature(const_precise_live_drops)] diff --git a/rust/alloc/raw_vec.rs b/rust/alloc/raw_vec.rs index 018c4657f58047..23f371d2ef7a72 100644 --- a/rust/alloc/raw_vec.rs +++ b/rust/alloc/raw_vec.rs @@ -276,9 +276,7 @@ impl RawVec { // We have an allocated chunk of memory, so we can bypass runtime // checks to get our current layout. unsafe { - let align = mem::align_of::(); - let size = mem::size_of::() * self.cap; - let layout = Layout::from_size_align_unchecked(size, align); + let layout = Layout::array::(self.cap).unwrap_unchecked(); Some((self.ptr.cast().into(), layout)) } } @@ -475,10 +473,11 @@ impl RawVec { assert!(cap <= self.capacity(), "Tried to shrink to a larger capacity"); let (ptr, layout) = if let Some(mem) = self.current_memory() { mem } else { return Ok(()) }; - let new_size = cap * mem::size_of::(); let ptr = unsafe { - let new_layout = Layout::from_size_align_unchecked(new_size, layout.align()); + // `Layout::array` cannot overflow here because it would have + // overflowed earlier when capacity was larger. + let new_layout = Layout::array::(cap).unwrap_unchecked(); self.alloc .shrink(ptr, layout, new_layout) .map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })? diff --git a/rust/alloc/slice.rs b/rust/alloc/slice.rs index 8cb5170f639d61..60a27e0329edaf 100644 --- a/rust/alloc/slice.rs +++ b/rust/alloc/slice.rs @@ -50,7 +50,7 @@ //! ``` //! let numbers = &[0, 1, 2]; //! for n in numbers { -//! println!("{} is a number!", n); +//! println!("{n} is a number!"); //! } //! ``` //! @@ -287,7 +287,7 @@ mod hack { } } -#[lang = "slice_alloc"] +#[cfg_attr(bootstrap, lang = "slice_alloc")] #[cfg(not(test))] impl [T] { /// Sorts the slice. @@ -317,6 +317,7 @@ impl [T] { /// assert!(v == [-5, -3, 1, 2, 4]); /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sort(&mut self) @@ -372,6 +373,7 @@ impl [T] { /// assert!(v == [5, 4, 3, 2, 1]); /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sort_by(&mut self, mut compare: F) @@ -413,6 +415,7 @@ impl [T] { /// assert!(v == [1, 2, -3, 4, -5]); /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "slice_sort_by_key", since = "1.7.0")] #[inline] pub fn sort_by_key(&mut self, mut f: F) @@ -459,6 +462,7 @@ impl [T] { /// /// [pdqsort]: https://github.com/orlp/pdqsort #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "slice_sort_by_cached_key", since = "1.34.0")] #[inline] pub fn sort_by_cached_key(&mut self, f: F) @@ -517,6 +521,7 @@ impl [T] { /// // Here, `s` and `x` can be modified independently. /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[rustc_conversion_suggestion] #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -536,6 +541,7 @@ impl [T] { /// let x = s.try_to_vec().unwrap(); /// // Here, `s` and `x` can be modified independently. /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[inline] #[stable(feature = "kernel", since = "1.0.0")] pub fn try_to_vec(&self) -> Result, TryReserveError> @@ -559,6 +565,7 @@ impl [T] { /// // Here, `s` and `x` can be modified independently. /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[inline] #[unstable(feature = "allocator_api", issue = "32838")] pub fn to_vec_in(&self, alloc: A) -> Vec @@ -582,6 +589,7 @@ impl [T] { /// let x = s.try_to_vec_in(System).unwrap(); /// // Here, `s` and `x` can be modified independently. /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[inline] #[stable(feature = "kernel", since = "1.0.0")] pub fn try_to_vec_in(&self, alloc: A) -> Result, TryReserveError> @@ -606,6 +614,7 @@ impl [T] { /// /// assert_eq!(x, vec![10, 40, 30]); /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn into_vec(self: Box) -> Vec { @@ -633,6 +642,7 @@ impl [T] { /// // this will panic at runtime /// b"0123456789abcdef".repeat(usize::MAX); /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[cfg(not(no_global_oom_handling))] #[stable(feature = "repeat_generic_slice", since = "1.40.0")] pub fn repeat(&self, n: usize) -> Vec @@ -701,6 +711,7 @@ impl [T] { /// assert_eq!(["hello", "world"].concat(), "helloworld"); /// assert_eq!([[1, 2], [3, 4]].concat(), [1, 2, 3, 4]); /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "rust1", since = "1.0.0")] pub fn concat(&self) -> >::Output where @@ -719,6 +730,7 @@ impl [T] { /// assert_eq!([[1, 2], [3, 4]].join(&0), [1, 2, 0, 3, 4]); /// assert_eq!([[1, 2], [3, 4]].join(&[0, 0][..]), [1, 2, 0, 0, 3, 4]); /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "rename_connect_to_join", since = "1.3.0")] pub fn join(&self, sep: Separator) -> >::Output where @@ -737,6 +749,7 @@ impl [T] { /// assert_eq!(["hello", "world"].connect(" "), "hello world"); /// assert_eq!([[1, 2], [3, 4]].connect(&0), [1, 2, 0, 3, 4]); /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated(since = "1.3.0", reason = "renamed to join")] pub fn connect(&self, sep: Separator) -> >::Output @@ -747,7 +760,7 @@ impl [T] { } } -#[lang = "slice_u8_alloc"] +#[cfg_attr(bootstrap, lang = "slice_u8_alloc")] #[cfg(not(test))] impl [u8] { /// Returns a vector containing a copy of this slice where each byte @@ -760,6 +773,7 @@ impl [u8] { /// /// [`make_ascii_uppercase`]: slice::make_ascii_uppercase #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "this returns the uppercase bytes as a new Vec, \ without modifying the original"] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] @@ -780,6 +794,7 @@ impl [u8] { /// /// [`make_ascii_lowercase`]: slice::make_ascii_lowercase #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "this returns the lowercase bytes as a new Vec, \ without modifying the original"] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] @@ -1134,9 +1149,9 @@ where impl Drop for MergeHole { fn drop(&mut self) { - // `T` is not a zero-sized type, so it's okay to divide by its size. - let len = (self.end as usize - self.start as usize) / mem::size_of::(); + // `T` is not a zero-sized type, and these are pointers into a slice's elements. unsafe { + let len = self.end.offset_from(self.start) as usize; ptr::copy_nonoverlapping(self.start, self.dest, len); } } diff --git a/rust/alloc/str.rs b/rust/alloc/str.rs index a1370c2d674c34..dbf915bc4f0cb6 100644 --- a/rust/alloc/str.rs +++ b/rust/alloc/str.rs @@ -238,7 +238,7 @@ impl ToOwned for str { } /// Methods for string slices. -#[lang = "str_alloc"] +#[cfg_attr(bootstrap, lang = "str_alloc")] #[cfg(not(test))] impl str { /// Converts a `Box` into a `Box<[u8]>` without copying or allocating. @@ -253,6 +253,7 @@ impl str { /// let boxed_bytes = boxed_str.into_boxed_bytes(); /// assert_eq!(*boxed_bytes, *s.as_bytes()); /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[stable(feature = "str_box_extras", since = "1.20.0")] #[must_use = "`self` will be dropped if the result is not used"] #[inline] @@ -283,6 +284,7 @@ impl str { /// assert_eq!(s, s.replace("cookie monster", "little lamb")); /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "this returns the replaced string as a new allocation, \ without modifying the original"] #[stable(feature = "rust1", since = "1.0.0")] @@ -323,6 +325,7 @@ impl str { /// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10)); /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "this returns the replaced string as a new allocation, \ without modifying the original"] #[stable(feature = "str_replacen", since = "1.16.0")] @@ -379,6 +382,7 @@ impl str { /// assert_eq!(new_year, new_year.to_lowercase()); /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "this returns the lowercase string as a new String, \ without modifying the original"] #[stable(feature = "unicode_case_mapping", since = "1.2.0")] @@ -461,6 +465,7 @@ impl str { /// assert_eq!("TSCHÜSS", s.to_uppercase()); /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "this returns the uppercase string as a new String, \ without modifying the original"] #[stable(feature = "unicode_case_mapping", since = "1.2.0")] @@ -496,6 +501,7 @@ impl str { /// assert_eq!(boxed_str.into_string(), string); /// ``` #[stable(feature = "box_str", since = "1.4.0")] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub fn into_string(self: Box) -> String { @@ -524,6 +530,7 @@ impl str { /// let huge = "0123456789abcdef".repeat(usize::MAX); /// ``` #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use] #[stable(feature = "repeat_str", since = "1.16.0")] pub fn repeat(&self, n: usize) -> String { @@ -552,6 +559,7 @@ impl str { /// [`make_ascii_uppercase`]: str::make_ascii_uppercase /// [`to_uppercase`]: #method.to_uppercase #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "to uppercase the value in-place, use `make_ascii_uppercase()`"] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[inline] @@ -584,6 +592,7 @@ impl str { /// [`make_ascii_lowercase`]: str::make_ascii_lowercase /// [`to_lowercase`]: #method.to_lowercase #[cfg(not(no_global_oom_handling))] + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[must_use = "to lowercase the value in-place, use `make_ascii_lowercase()`"] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[inline] @@ -604,6 +613,7 @@ impl str { /// let s: &str = "a"; /// let ss: String = s.try_to_owned().unwrap(); /// ``` + #[cfg_attr(not(bootstrap), rustc_allow_incoherent_impl)] #[inline] #[stable(feature = "kernel", since = "1.0.0")] pub fn try_to_owned(&self) -> Result { diff --git a/rust/alloc/string.rs b/rust/alloc/string.rs index 5b9780cfc11f75..34997b477cd15e 100644 --- a/rust/alloc/string.rs +++ b/rust/alloc/string.rs @@ -1040,7 +1040,7 @@ impl String { } /// Tries to reserve the minimum capacity for exactly `additional` more elements to - /// be inserted in the given `String`. After calling `reserve_exact`, + /// be inserted in the given `String`. After calling `try_reserve_exact`, /// capacity will be greater than or equal to `self.len() + additional`. /// Does nothing if the capacity is already sufficient. /// @@ -2720,7 +2720,7 @@ impl From for Vec { /// let v1 = Vec::from(s1); /// /// for b in v1 { - /// println!("{}", b); + /// println!("{b}"); /// } /// ``` fn from(string: String) -> Vec { diff --git a/rust/alloc/vec/into_iter.rs b/rust/alloc/vec/into_iter.rs index 11d01ac868ca9c..d434d70ea9115b 100644 --- a/rust/alloc/vec/into_iter.rs +++ b/rust/alloc/vec/into_iter.rs @@ -1,5 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT +#[cfg(not(no_global_oom_handling))] +use super::AsVecIntoIter; use crate::alloc::{Allocator, Global}; use crate::raw_vec::RawVec; use core::fmt; @@ -8,7 +10,9 @@ use core::iter::{ FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce, }; use core::marker::PhantomData; -use core::mem::{self}; +use core::mem::{self, ManuallyDrop}; +#[cfg(not(no_global_oom_handling))] +use core::ops::Deref; use core::ptr::{self, NonNull}; use core::slice::{self}; @@ -32,7 +36,9 @@ pub struct IntoIter< pub(super) buf: NonNull, pub(super) phantom: PhantomData, pub(super) cap: usize, - pub(super) alloc: A, + // the drop impl reconstructs a RawVec from buf, cap and alloc + // to avoid dropping the allocator twice we need to wrap it into ManuallyDrop + pub(super) alloc: ManuallyDrop, pub(super) ptr: *const T, pub(super) end: *const T, } @@ -99,6 +105,9 @@ impl IntoIter { /// (&mut into_iter).for_each(core::mem::drop); /// unsafe { core::ptr::write(&mut into_iter, Vec::new().into_iter()); } /// ``` + /// + /// This method is used by in-place iteration, refer to the vec::in_place_collect + /// documentation for an overview. #[cfg(not(no_global_oom_handling))] pub(super) fn forget_allocation_drop_remaining(&mut self) { let remaining = self.as_raw_mut_slice(); @@ -156,7 +165,7 @@ impl Iterator for IntoIter { #[inline] fn size_hint(&self) -> (usize, Option) { let exact = if mem::size_of::() == 0 { - (self.end as usize).wrapping_sub(self.ptr as usize) + self.end.addr().wrapping_sub(self.ptr.addr()) } else { unsafe { self.end.offset_from(self.ptr) as usize } }; @@ -292,11 +301,11 @@ where impl Clone for IntoIter { #[cfg(not(test))] fn clone(&self) -> Self { - self.as_slice().to_vec_in(self.alloc.clone()).into_iter() + self.as_slice().to_vec_in(self.alloc.deref().clone()).into_iter() } #[cfg(test)] fn clone(&self) -> Self { - crate::slice::to_vec(self.as_slice(), self.alloc.clone()).into_iter() + crate::slice::to_vec(self.as_slice(), self.alloc.deref().clone()).into_iter() } } @@ -308,8 +317,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter { impl Drop for DropGuard<'_, T, A> { fn drop(&mut self) { unsafe { - // `IntoIter::alloc` is not used anymore after this - let alloc = ptr::read(&self.0.alloc); + // `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec + let alloc = ManuallyDrop::take(&mut self.0.alloc); // RawVec handles deallocation let _ = RawVec::from_raw_parts_in(self.0.buf.as_ptr(), self.0.cap, alloc); } @@ -325,6 +334,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter { } } +// In addition to the SAFETY invariants of the following three unsafe traits +// also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] unsafe impl InPlaceIterable for IntoIter {} @@ -340,14 +351,8 @@ unsafe impl SourceIter for IntoIter { } } -// internal helper trait for in-place iteration specialization. -#[rustc_specialization_trait] -pub(crate) trait AsIntoIter { - type Item; - fn as_into_iter(&mut self) -> &mut IntoIter; -} - -impl AsIntoIter for IntoIter { +#[cfg(not(no_global_oom_handling))] +unsafe impl AsVecIntoIter for IntoIter { type Item = T; fn as_into_iter(&mut self) -> &mut IntoIter { diff --git a/rust/alloc/vec/mod.rs b/rust/alloc/vec/mod.rs index a2b1dfca35614b..7747f8b94af596 100644 --- a/rust/alloc/vec/mod.rs +++ b/rust/alloc/vec/mod.rs @@ -98,7 +98,7 @@ mod drain; mod cow; #[cfg(not(no_global_oom_handling))] -pub(crate) use self::into_iter::AsIntoIter; +pub(crate) use self::in_place_collect::AsVecIntoIter; #[stable(feature = "rust1", since = "1.0.0")] pub use self::into_iter::IntoIter; @@ -110,7 +110,7 @@ use self::is_zero::IsZero; mod is_zero; #[cfg(not(no_global_oom_handling))] -mod source_iter_marker; +mod in_place_collect; mod partial_eq; @@ -170,7 +170,7 @@ mod spec_extend; /// vec.extend([1, 2, 3].iter().copied()); /// /// for x in &vec { -/// println!("{}", x); +/// println!("{x}"); /// } /// assert_eq!(vec, [7, 1, 2, 3]); /// ``` @@ -212,7 +212,7 @@ mod spec_extend; /// /// while let Some(top) = stack.pop() { /// // Prints 3, 2, 1 -/// println!("{}", top); +/// println!("{top}"); /// } /// ``` /// @@ -523,12 +523,14 @@ impl Vec { /// /// * `ptr` needs to have been previously allocated via [`String`]/`Vec` /// (at least, it's highly likely to be incorrect if it wasn't). - /// * `T` needs to have the same size and alignment as what `ptr` was allocated with. + /// * `T` needs to have the same alignment as what `ptr` was allocated with. /// (`T` having a less strict alignment is not sufficient, the alignment really /// needs to be equal to satisfy the [`dealloc`] requirement that memory must be /// allocated and deallocated with the same layout.) + /// * The size of `T` times the `capacity` (ie. the allocated size in bytes) needs + /// to be the same size as the pointer was allocated with. (Because similar to + /// alignment, [`dealloc`] must be called with the same layout `size`.) /// * `length` needs to be less than or equal to `capacity`. - /// * `capacity` needs to be the capacity that the pointer was allocated with. /// /// Violating these may cause problems like corrupting the allocator's /// internal data structures. For example it is **not** safe @@ -536,7 +538,9 @@ impl Vec { /// It's also not safe to build one from a `Vec` and its length, because /// the allocator cares about the alignment, and these two types have different /// alignments. The buffer was allocated with alignment 2 (for `u16`), but after - /// turning it into a `Vec` it'll be deallocated with alignment 1. + /// turning it into a `Vec` it'll be deallocated with alignment 1. To avoid + /// these issues, it is often preferable to do casting/transmuting using + /// [`slice::from_raw_parts`] instead. /// /// The ownership of `ptr` is effectively transferred to the /// `Vec` which may then deallocate, reallocate or change the @@ -1450,7 +1454,7 @@ impl Vec { #[cold] #[inline(never)] fn assert_failed(index: usize, len: usize) -> ! { - panic!("swap_remove index (is {}) should be < len (is {})", index, len); + panic!("swap_remove index (is {index}) should be < len (is {len})"); } let len = self.len(); @@ -1491,7 +1495,7 @@ impl Vec { #[cold] #[inline(never)] fn assert_failed(index: usize, len: usize) -> ! { - panic!("insertion index (is {}) should be <= len (is {})", index, len); + panic!("insertion index (is {index}) should be <= len (is {len})"); } let len = self.len(); @@ -1550,7 +1554,7 @@ impl Vec { #[inline(never)] #[track_caller] fn assert_failed(index: usize, len: usize) -> ! { - panic!("removal index (is {}) should be < len (is {})", index, len); + panic!("removal index (is {index}) should be < len (is {len})"); } let len = self.len(); @@ -1577,7 +1581,7 @@ impl Vec { /// Retains only the elements specified by the predicate. /// - /// In other words, remove all elements `e` such that `f(&e)` returns `false`. + /// In other words, remove all elements `e` for which `f(&e)` returns `false`. /// This method operates in place, visiting each element exactly once in the /// original order, and preserves the order of the retained elements. /// @@ -1616,8 +1620,6 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(vec_retain_mut)] - /// /// let mut vec = vec![1, 2, 3, 4]; /// vec.retain_mut(|x| if *x > 3 { /// false @@ -1627,7 +1629,7 @@ impl Vec { /// }); /// assert_eq!(vec, [2, 3, 4]); /// ``` - #[unstable(feature = "vec_retain_mut", issue = "90829")] + #[stable(feature = "vec_retain_mut", since = "1.61.0")] pub fn retain_mut(&mut self, mut f: F) where F: FnMut(&mut T) -> bool, @@ -1939,7 +1941,7 @@ impl Vec { } } - /// Moves all the elements of `other` into `Self`, leaving `other` empty. + /// Moves all the elements of `other` into `self`, leaving `other` empty. /// /// # Panics /// @@ -1964,7 +1966,7 @@ impl Vec { } } - /// Appends elements to `Self` from other buffer. + /// Appends elements to `self` from other buffer. #[cfg(not(no_global_oom_handling))] #[inline] unsafe fn append_elements(&mut self, other: *const [T]) { @@ -2129,7 +2131,7 @@ impl Vec { #[cold] #[inline(never)] fn assert_failed(at: usize, len: usize) -> ! { - panic!("`at` split index (is {}) should be <= len (is {})", at, len); + panic!("`at` split index (is {at}) should be <= len (is {len})"); } if at > self.len() { @@ -2847,14 +2849,14 @@ impl IntoIterator for Vec { /// let v = vec!["a".to_string(), "b".to_string()]; /// for s in v.into_iter() { /// // s has type String, not &String - /// println!("{}", s); + /// println!("{s}"); /// } /// ``` #[inline] fn into_iter(self) -> IntoIter { unsafe { let mut me = ManuallyDrop::new(self); - let alloc = ptr::read(me.allocator()); + let alloc = ManuallyDrop::new(ptr::read(me.allocator())); let begin = me.as_mut_ptr(); let end = if mem::size_of::() == 0 { arith_offset(begin as *const i8, me.len() as isize) as *const T diff --git a/rust/alloc/vec/partial_eq.rs b/rust/alloc/vec/partial_eq.rs index 273e99bed4888e..10ad4e492287b9 100644 --- a/rust/alloc/vec/partial_eq.rs +++ b/rust/alloc/vec/partial_eq.rs @@ -22,7 +22,7 @@ macro_rules! __impl_slice_eq1 { } } -__impl_slice_eq1! { [A: Allocator] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [A1: Allocator, A2: Allocator] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")] } __impl_slice_eq1! { [A: Allocator] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")] } __impl_slice_eq1! { [A: Allocator] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")] } __impl_slice_eq1! { [A: Allocator] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] } diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 8ec73f18cc021c..e569e3dce79819 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -15,7 +15,6 @@ #![feature(allocator_api)] #![feature(associated_type_defaults)] #![feature(concat_idents)] -#![feature(const_fn_trait_bound)] #![feature(const_mut_refs)] #![feature(const_ptr_offset_from)] #![feature(const_refs_to_cell)] diff --git a/scripts/min-tool-version.sh b/scripts/min-tool-version.sh index 53fe64856015ba..6499f0dcf33b95 100755 --- a/scripts/min-tool-version.sh +++ b/scripts/min-tool-version.sh @@ -32,7 +32,7 @@ llvm) fi ;; rustc) - echo 1.60.0 + echo 1.61.0 ;; bindgen) echo 0.56.0