diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a5efd8e5fdc2e7..4bcbcabdf1cb8e 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.59.0 + container: ghcr.io/rust-for-linux/ci:Rust-1.60.0 timeout-minutes: 20 strategy: diff --git a/Documentation/process/changes.rst b/Documentation/process/changes.rst index ee22bd1da334d1..a886ac497266b5 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.59.0 rustc --version +Rust (optional) 1.60.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/Makefile b/rust/Makefile index fd0f04a504b9a3..1c86503de0368b 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -348,8 +348,8 @@ rust-analyzer: $(RUST_LIB_SRC) > $(objtree)/rust-project.json $(obj)/core.o: private skip_clippy = 1 -$(obj)/core.o: private skip_flags = -Dunreachable_pub --edition=2021 -$(obj)/core.o: private rustc_target_flags = $(core-cfgs) --edition=2018 +$(obj)/core.o: private skip_flags = -Dunreachable_pub +$(obj)/core.o: private rustc_target_flags = $(core-cfgs) $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs $(obj)/target.json FORCE $(call if_changed_dep,rustc_library) diff --git a/rust/alloc/alloc.rs b/rust/alloc/alloc.rs index e594448bf49e3e..cea3b747673fd6 100644 --- a/rust/alloc/alloc.rs +++ b/rust/alloc/alloc.rs @@ -350,7 +350,6 @@ extern "Rust" { // This is the magic symbol to call the global alloc error handler. rustc generates // it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the // default implementations below (`__rdl_oom`) otherwise. - #[rustc_allocator_nounwind] fn __rust_alloc_error_handler(size: usize, align: usize) -> !; } @@ -369,7 +368,6 @@ extern "Rust" { #[stable(feature = "global_alloc", since = "1.28.0")] #[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")] #[cfg(all(not(no_global_oom_handling), not(test)))] -#[rustc_allocator_nounwind] #[cold] pub const fn handle_alloc_error(layout: Layout) -> ! { const fn ct_error(_: Layout) -> ! { @@ -400,13 +398,13 @@ pub mod __alloc_error_handler { // if there is no `#[alloc_error_handler]` #[rustc_std_internal_symbol] - pub unsafe extern "C" fn __rdl_oom(size: usize, _align: usize) -> ! { + pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! { panic!("memory allocation of {} bytes failed", size) } // if there is an `#[alloc_error_handler]` #[rustc_std_internal_symbol] - pub unsafe extern "C" fn __rg_oom(size: usize, align: usize) -> ! { + pub unsafe extern "C-unwind" fn __rg_oom(size: usize, align: usize) -> ! { let layout = unsafe { Layout::from_size_align_unchecked(size, align) }; extern "Rust" { #[lang = "oom"] diff --git a/rust/alloc/boxed.rs b/rust/alloc/boxed.rs index 3a827dbb6e443e..921fcef75e4b9b 100644 --- a/rust/alloc/boxed.rs +++ b/rust/alloc/boxed.rs @@ -135,6 +135,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use core::any::Any; +use core::async_iter::AsyncIterator; use core::borrow; use core::cmp::Ordering; use core::convert::{From, TryFrom}; @@ -151,7 +152,6 @@ use core::ops::{ }; use core::pin::Pin; use core::ptr::{self, Unique}; -use core::stream::Stream; use core::task::{Context, Poll}; #[cfg(not(no_global_oom_handling))] @@ -1172,8 +1172,7 @@ impl Box { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_box", issue = "92521")] -unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> const Drop for Box { +unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box { fn drop(&mut self) { // FIXME: Do nothing, drop is currently performed by compiler. } @@ -1994,8 +1993,8 @@ where } } -#[unstable(feature = "async_stream", issue = "79024")] -impl Stream for Box { +#[unstable(feature = "async_iterator", issue = "79024")] +impl AsyncIterator for Box { type Item = S::Item; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { diff --git a/rust/alloc/collections/mod.rs b/rust/alloc/collections/mod.rs index 4954ed880c4a06..1eec265b28f807 100644 --- a/rust/alloc/collections/mod.rs +++ b/rust/alloc/collections/mod.rs @@ -16,7 +16,7 @@ pub mod vec_deque; #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] pub mod btree_map { - //! A map based on a B-Tree. + //! An ordered map based on a B-Tree. #[stable(feature = "rust1", since = "1.0.0")] pub use super::btree::map::*; } @@ -24,7 +24,7 @@ pub mod btree_map { #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] pub mod btree_set { - //! A set based on a B-Tree. + //! An ordered set based on a B-Tree. #[stable(feature = "rust1", since = "1.0.0")] pub use super::btree::set::*; } diff --git a/rust/alloc/fmt.rs b/rust/alloc/fmt.rs index c4c99f7c3287cb..be75e6637442e3 100644 --- a/rust/alloc/fmt.rs +++ b/rust/alloc/fmt.rs @@ -76,7 +76,7 @@ //! identifier '=' expression //! ``` //! -//! For example, the following [`format!`] expressions all use named argument: +//! For example, the following [`format!`] expressions all use named arguments: //! //! ``` //! format!("{argument}", argument = "test"); // => "test" diff --git a/rust/alloc/lib.rs b/rust/alloc/lib.rs index 6f7c466abf3216..085dc005170a05 100644 --- a/rust/alloc/lib.rs +++ b/rust/alloc/lib.rs @@ -69,17 +69,14 @@ issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", test(no_crate_inject, attr(allow(unused_variables), deny(warnings))) )] -#![cfg_attr( - not(bootstrap), - doc(cfg_hide( - not(test), - not(any(test, bootstrap)), - any(not(feature = "miri-test-libstd"), test, doctest), - no_global_oom_handling, - not(no_global_oom_handling), - target_has_atomic = "ptr" - )) -)] +#![doc(cfg_hide( + not(test), + not(any(test, bootstrap)), + any(not(feature = "miri-test-libstd"), test, doctest), + no_global_oom_handling, + not(no_global_oom_handling), + target_has_atomic = "ptr" +))] #![no_std] #![needs_allocator] // @@ -96,7 +93,7 @@ #![feature(array_chunks)] #![feature(array_methods)] #![feature(array_windows)] -#![feature(async_stream)] +#![feature(async_iterator)] #![feature(coerce_unsized)] #![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))] #![feature(const_box)] @@ -117,11 +114,9 @@ #![feature(extend_one)] #![feature(fmt_internals)] #![feature(fn_traits)] -#![feature(inherent_ascii_escape)] #![feature(inplace_iteration)] #![feature(iter_advance_by)] #![feature(layout_for_ptr)] -#![feature(maybe_uninit_extra)] #![feature(maybe_uninit_slice)] #![cfg_attr(test, feature(new_uninit))] #![feature(nonnull_slice_from_raw_parts)] @@ -146,7 +141,7 @@ #![feature(associated_type_bounds)] #![feature(box_syntax)] #![feature(cfg_sanitize)] -#![feature(cfg_target_has_atomic)] +#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))] #![feature(const_deref)] #![feature(const_fn_trait_bound)] #![feature(const_mut_refs)] @@ -154,7 +149,6 @@ #![feature(const_precise_live_drops)] #![feature(const_trait_impl)] #![feature(const_try)] -#![cfg_attr(bootstrap, feature(destructuring_assignment))] #![feature(dropck_eyepatch)] #![feature(exclusive_range_pattern)] #![feature(fundamental)] @@ -170,6 +164,7 @@ #![cfg_attr(test, feature(test))] #![feature(unboxed_closures)] #![feature(unsized_fn_params)] +#![feature(c_unwind)] // // Rustdoc features: #![feature(doc_cfg)] diff --git a/rust/alloc/macros.rs b/rust/alloc/macros.rs index 73c43515241848..47ebcd5277d16c 100644 --- a/rust/alloc/macros.rs +++ b/rust/alloc/macros.rs @@ -39,6 +39,7 @@ #[cfg(all(not(no_global_oom_handling), not(test)))] #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_diagnostic_item = "vec_macro"] #[allow_internal_unstable(box_syntax, liballoc_internals)] macro_rules! vec { () => ( diff --git a/rust/alloc/raw_vec.rs b/rust/alloc/raw_vec.rs index bbce7d012c6b1d..018c4657f58047 100644 --- a/rust/alloc/raw_vec.rs +++ b/rust/alloc/raw_vec.rs @@ -110,7 +110,7 @@ impl RawVec { // to round up a request of less than 8 bytes to at least 8 bytes. // - 4 if elements are moderate-sized (<= 1 KiB). // - 1 otherwise, to avoid wasting too much space for very short Vecs. - const MIN_NON_ZERO_CAP: usize = if mem::size_of::() == 1 { + pub(crate) const MIN_NON_ZERO_CAP: usize = if mem::size_of::() == 1 { 8 } else if mem::size_of::() <= 1024 { 4 @@ -341,6 +341,12 @@ impl RawVec { } } + /// The same as `reserve_for_push`, but returns on errors instead of panicking or aborting. + #[inline(never)] + pub fn try_reserve_for_push(&mut self, len: usize) -> Result<(), TryReserveError> { + self.grow_amortized(len, 1) + } + /// Ensures that the buffer contains at least enough space to hold `len + /// additional` elements. If it doesn't already, will reallocate the /// minimum possible amount of memory necessary. Generally this will be diff --git a/rust/alloc/slice.rs b/rust/alloc/slice.rs index e2ea09cbb231bf..8cb5170f639d61 100644 --- a/rust/alloc/slice.rs +++ b/rust/alloc/slice.rs @@ -110,7 +110,7 @@ pub use core::slice::ArrayChunks; pub use core::slice::ArrayChunksMut; #[unstable(feature = "array_windows", issue = "75027")] pub use core::slice::ArrayWindows; -#[unstable(feature = "inherent_ascii_escape", issue = "77174")] +#[stable(feature = "inherent_ascii_escape", since = "1.60.0")] pub use core::slice::EscapeAscii; #[stable(feature = "slice_get_slice", since = "1.28.0")] pub use core::slice::SliceIndex; @@ -425,7 +425,10 @@ impl [T] { /// Sorts the slice with a key extraction function. /// - /// During sorting, the key function is called only once per element. + /// During sorting, the key function is called at most once per element, by using + /// temporary storage to remember the results of key evaluation. + /// The order of calls to the key function is unspecified and may change in future versions + /// of the standard library. /// /// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* + *n* \* log(*n*)) /// worst-case, where the key function is *O*(*m*). diff --git a/rust/alloc/string.rs b/rust/alloc/string.rs index e38ca61ee5cd84..5b9780cfc11f75 100644 --- a/rust/alloc/string.rs +++ b/rust/alloc/string.rs @@ -1630,17 +1630,24 @@ impl String { self.vec.clear() } - /// Creates a draining iterator that removes the specified range in the `String` - /// and yields the removed `chars`. + /// Removes the specified range from the string in bulk, returning all + /// removed characters as an iterator. /// - /// Note: The element range is removed even if the iterator is not - /// consumed until the end. + /// The returned iterator keeps a mutable borrow on the string to optimize + /// its implementation. /// /// # Panics /// /// Panics if the starting point or end point do not lie on a [`char`] /// boundary, or if they're out of bounds. /// + /// # Leaking + /// + /// If the returned iterator goes out of scope without being dropped (due to + /// [`core::mem::forget`], for example), the string may still contain a copy + /// of any drained characters, or may have lost characters arbitrarily, + /// including characters outside the range. + /// /// # Examples /// /// Basic usage: @@ -1654,7 +1661,7 @@ impl String { /// assert_eq!(t, "α is alpha, "); /// assert_eq!(s, "β is beta"); /// - /// // A full range clears the string + /// // A full range clears the string, like `clear()` does /// s.drain(..); /// assert_eq!(s, ""); /// ``` diff --git a/rust/alloc/vec/into_iter.rs b/rust/alloc/vec/into_iter.rs index 7acd7fb5a09d4d..11d01ac868ca9c 100644 --- a/rust/alloc/vec/into_iter.rs +++ b/rust/alloc/vec/into_iter.rs @@ -127,7 +127,7 @@ impl AsRef<[T]> for IntoIter { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Send for IntoIter {} #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Sync for IntoIter {} +unsafe impl Sync for IntoIter {} #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for IntoIter { diff --git a/rust/alloc/vec/mod.rs b/rust/alloc/vec/mod.rs index 8b3a731948a24b..a2b1dfca35614b 100644 --- a/rust/alloc/vec/mod.rs +++ b/rust/alloc/vec/mod.rs @@ -1525,9 +1525,12 @@ impl Vec { /// /// Note: Because this shifts over the remaining elements, it has a /// worst-case performance of *O*(*n*). If you don't need the order of elements - /// to be preserved, use [`swap_remove`] instead. + /// to be preserved, use [`swap_remove`] instead. If you'd like to remove + /// elements from the beginning of the `Vec`, consider using + /// [`VecDeque::pop_front`] instead. /// /// [`swap_remove`]: Vec::swap_remove + /// [`VecDeque::pop_front`]: crate::collections::VecDeque::pop_front /// /// # Panics /// @@ -1898,7 +1901,7 @@ impl Vec { #[stable(feature = "kernel", since = "1.0.0")] pub fn try_push(&mut self, value: T) -> Result<(), TryReserveError> { if self.len == self.buf.capacity() { - self.try_reserve(1)?; + self.buf.try_reserve_for_push(self.len)?; } unsafe { let end = self.as_mut_ptr().add(self.len); @@ -1911,6 +1914,11 @@ impl Vec { /// Removes the last element from a vector and returns it, or [`None`] if it /// is empty. /// + /// If you'd like to pop the first element, consider using + /// [`VecDeque::pop_front`] instead. + /// + /// [`VecDeque::pop_front`]: crate::collections::VecDeque::pop_front + /// /// # Examples /// /// ``` @@ -1978,19 +1986,24 @@ impl Vec { Ok(()) } - /// Creates a draining iterator that removes the specified range in the vector - /// and yields the removed items. + /// Removes the specified range from the vector in bulk, returning all + /// removed elements as an iterator. If the iterator is dropped before + /// being fully consumed, it drops the remaining removed elements. /// - /// When the iterator **is** dropped, all elements in the range are removed - /// from the vector, even if the iterator was not fully consumed. If the - /// iterator **is not** dropped (with [`mem::forget`] for example), it is - /// unspecified how many elements are removed. + /// The returned iterator keeps a mutable borrow on the vector to optimize + /// its implementation. /// /// # Panics /// /// Panics if the starting point is greater than the end point or if /// the end point is greater than the length of the vector. /// + /// # Leaking + /// + /// If the returned iterator goes out of scope without being dropped (due to + /// [`mem::forget`], for example), the vector may have lost and leaked + /// elements arbitrarily, including elements outside the range. + /// /// # Examples /// /// ``` @@ -1999,7 +2012,7 @@ impl Vec { /// assert_eq!(v, &[1]); /// assert_eq!(u, &[2, 3]); /// - /// // A full range clears the vector + /// // A full range clears the vector, like `clear()` does /// v.drain(..); /// assert_eq!(v, &[]); /// ``` @@ -2230,8 +2243,6 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(vec_spare_capacity)] - /// /// // Allocate vector big enough for 10 elements. /// let mut v = Vec::with_capacity(10); /// @@ -2248,7 +2259,7 @@ impl Vec { /// /// assert_eq!(&v, &[0, 1, 2]); /// ``` - #[unstable(feature = "vec_spare_capacity", issue = "75017")] + #[stable(feature = "vec_spare_capacity", since = "1.60.0")] #[inline] pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit] { // Note: @@ -2451,7 +2462,7 @@ impl Vec { /// Tries to clone and append all elements in a slice to the `Vec`. /// /// Iterates over the slice `other`, clones each element, and then appends - /// it to this `Vec`. The `other` vector is traversed in-order. + /// it to this `Vec`. The `other` slice is traversed in-order. /// /// Note that this function is same as [`extend`] except that it is /// specialized to work with slices instead. If and when Rust gets @@ -3207,10 +3218,6 @@ impl From<&mut [T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_array", since = "1.44.0")] impl From<[T; N]> for Vec { - #[cfg(not(test))] - fn from(s: [T; N]) -> Vec { - <[T]>::into_vec(box s) - } /// Allocate a `Vec` and move `s`'s items into it. /// /// # Examples @@ -3218,6 +3225,11 @@ impl From<[T; N]> for Vec { /// ``` /// assert_eq!(Vec::from([1, 2, 3]), vec![1, 2, 3]); /// ``` + #[cfg(not(test))] + fn from(s: [T; N]) -> Vec { + <[T]>::into_vec(box s) + } + #[cfg(test)] fn from(s: [T; N]) -> Vec { crate::slice::into_vec(box s) @@ -3311,14 +3323,12 @@ impl TryFrom> for [T; N] { /// # Examples /// /// ``` - /// use std::convert::TryInto; /// assert_eq!(vec![1, 2, 3].try_into(), Ok([1, 2, 3])); /// assert_eq!(>::new().try_into(), Ok([])); /// ``` /// /// If the length doesn't match, the input comes back in `Err`: /// ``` - /// use std::convert::TryInto; /// let r: Result<[i32; 4], _> = (0..10).collect::>().try_into(); /// assert_eq!(r, Err(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); /// ``` @@ -3326,7 +3336,6 @@ impl TryFrom> for [T; N] { /// If you're fine with just getting a prefix of the `Vec`, /// you can call [`.truncate(N)`](Vec::truncate) first. /// ``` - /// use std::convert::TryInto; /// let mut v = String::from("hello world").into_bytes(); /// v.sort(); /// v.truncate(2); diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index b1963d4d315d80..fafb20d28eff58 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -22,7 +22,6 @@ #![feature(const_trait_impl)] #![feature(doc_cfg)] #![feature(generic_associated_types)] -#![feature(maybe_uninit_extra)] #![feature(ptr_metadata)] #![feature(receiver_trait)] #![feature(coerce_unsized)] diff --git a/scripts/min-tool-version.sh b/scripts/min-tool-version.sh index 2fc305342fa1b4..53fe64856015ba 100755 --- a/scripts/min-tool-version.sh +++ b/scripts/min-tool-version.sh @@ -32,7 +32,7 @@ llvm) fi ;; rustc) - echo 1.59.0 + echo 1.60.0 ;; bindgen) echo 0.56.0