Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust 1.57 #586

Merged
merged 8 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
arch: [arm, arm64, ppc64le, riscv64, x86_64]
toolchain: [gcc, clang, llvm]
config: [debug, release]
rustc: [1.56.0]
rustc: [1.57.0]
output: [src] # [src, build]
install: [rustup] # [rustup, standalone]
sysroot: [common] # [common, custom]
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- arch: arm64
toolchain: gcc
config: debug
rustc: 1.56.0
rustc: 1.57.0
output: build
install: rustup
sysroot: custom
Expand All @@ -58,7 +58,7 @@ jobs:
- arch: arm64
toolchain: llvm
config: debug
rustc: 1.56.0
rustc: 1.57.0
output: build
install: rustup
sysroot: custom
Expand All @@ -67,7 +67,7 @@ jobs:
- arch: arm64
toolchain: llvm
config: release
rustc: 1.56.0
rustc: 1.57.0
output: build
install: rustup
sysroot: custom
Expand All @@ -76,7 +76,7 @@ jobs:
- arch: ppc64le
toolchain: clang
config: release
rustc: 1.56.0
rustc: 1.57.0
output: build
install: standalone
sysroot: common
Expand All @@ -85,7 +85,7 @@ jobs:
- arch: x86_64
toolchain: llvm
config: debug
rustc: 1.56.0
rustc: 1.57.0
output: build
install: standalone
sysroot: custom
Expand All @@ -94,7 +94,7 @@ jobs:
- arch: x86_64
toolchain: llvm
config: debug
rustc: 1.56.0
rustc: 1.57.0
output: src
install: rustup
sysroot: common
Expand All @@ -103,7 +103,7 @@ jobs:
- arch: x86_64
toolchain: llvm
config: release
rustc: 1.56.0
rustc: 1.57.0
output: src
install: rustup
sysroot: common
Expand Down
2 changes: 1 addition & 1 deletion Documentation/process/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ know what you are doing, use the exact version listed here. Please see
====================== =============== ========================================
GNU C 5.1 gcc --version
Clang/LLVM (optional) 10.0.1 clang --version
rustc (optional) 1.56.0 rustc --version
rustc (optional) 1.57.0 rustc --version
bindgen (optional) 0.56.0 bindgen --version
GNU make 3.81 make --version
binutils 2.23 ld -v
Expand Down
2 changes: 1 addition & 1 deletion Documentation/rust/quick-start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Rust features.
If ``rustup`` is being used, enter the checked out source code directory
and run::

rustup override set 1.56.0
rustup override set 1.57.0

Otherwise, fetch a standalone installer or install ``rustup`` from:

Expand Down
8 changes: 1 addition & 7 deletions drivers/android/rust_binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
//! TODO: This module is a work in progress.

#![no_std]
#![feature(
global_asm,
try_reserve,
allocator_api,
concat_idents,
generic_associated_types
)]
#![feature(global_asm, allocator_api, concat_idents, generic_associated_types)]

use kernel::{
io_buffer::IoBufferWriter,
Expand Down
1 change: 0 additions & 1 deletion rust/alloc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ unsafe impl Allocator for Global {
}

/// The allocator for unique pointers.
// This function must not unwind. If it does, MIR codegen will fail.
#[cfg(all(not(no_global_oom_handling), not(test)))]
#[lang = "exchange_malloc"]
#[inline]
Expand Down
6 changes: 5 additions & 1 deletion rust/alloc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<B: ?Sized + ToOwned> Deref for Cow<'_, B> {
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
impl<B: ?Sized + ToOwned> const Deref for Cow<'_, B>
where
B::Owned: ~const Borrow<B>,
{
type Target = B;

fn deref(&self) -> &B {
Expand Down
55 changes: 55 additions & 0 deletions rust/alloc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ impl<T> Box<T> {
#[cfg(not(no_global_oom_handling))]
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
pub fn new(x: T) -> Self {
box x
}
Expand All @@ -213,6 +214,7 @@ impl<T> Box<T> {
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
#[inline]
pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
Self::new_uninit_in(Global)
Expand All @@ -239,6 +241,7 @@ impl<T> Box<T> {
#[cfg(not(no_global_oom_handling))]
#[inline]
#[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
Self::new_zeroed_in(Global)
}
Expand All @@ -247,6 +250,7 @@ impl<T> Box<T> {
/// `x` will be pinned in memory and unable to be moved.
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "pin", since = "1.33.0")]
#[must_use]
#[inline(always)]
pub fn pin(x: T) -> Pin<Box<T>> {
(box x).into()
Expand Down Expand Up @@ -341,6 +345,7 @@ impl<T, A: Allocator> Box<T, A> {
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "allocator_api", issue = "32838")]
#[must_use]
#[inline]
pub fn new_in(x: T, alloc: A) -> Self {
let mut boxed = Self::new_uninit_in(alloc);
Expand Down Expand Up @@ -397,6 +402,7 @@ impl<T, A: Allocator> Box<T, A> {
/// ```
#[unstable(feature = "allocator_api", issue = "32838")]
#[cfg(not(no_global_oom_handling))]
#[must_use]
// #[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> {
let layout = Layout::new::<mem::MaybeUninit<T>>();
Expand Down Expand Up @@ -461,6 +467,7 @@ impl<T, A: Allocator> Box<T, A> {
#[unstable(feature = "allocator_api", issue = "32838")]
#[cfg(not(no_global_oom_handling))]
// #[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> {
let layout = Layout::new::<mem::MaybeUninit<T>>();
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
Expand Down Expand Up @@ -505,6 +512,7 @@ impl<T, A: Allocator> Box<T, A> {
/// `x` will be pinned in memory and unable to be moved.
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "allocator_api", issue = "32838")]
#[must_use]
#[inline(always)]
pub fn pin_in(x: T, alloc: A) -> Pin<Self>
where
Expand Down Expand Up @@ -563,6 +571,7 @@ impl<T> Box<[T]> {
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
unsafe { RawVec::with_capacity(len).into_box(len) }
}
Expand All @@ -587,6 +596,7 @@ impl<T> Box<[T]> {
/// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
unsafe { RawVec::with_capacity_zeroed(len).into_box(len) }
}
Expand Down Expand Up @@ -683,6 +693,7 @@ impl<T, A: Allocator> Box<[T], A> {
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "allocator_api", issue = "32838")]
// #[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
unsafe { RawVec::with_capacity_in(len, alloc).into_box(len) }
}
Expand Down Expand Up @@ -710,6 +721,7 @@ impl<T, A: Allocator> Box<[T], A> {
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "allocator_api", issue = "32838")]
// #[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
unsafe { RawVec::with_capacity_zeroed_in(len, alloc).into_box(len) }
}
Expand Down Expand Up @@ -1088,6 +1100,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Box<T> {
/// Creates a `Box<T>`, with the `Default` value for T.
Expand Down Expand Up @@ -1278,6 +1291,7 @@ impl<T> From<T> for Box<T> {
/// from the stack into it.
///
/// # Examples
///
/// ```rust
/// let x = 5;
/// let boxed = Box::new(5);
Expand Down Expand Up @@ -1331,6 +1345,12 @@ impl<T: Copy> From<&[T]> for Box<[T]> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_from_cow", since = "1.45.0")]
impl<T: Copy> From<Cow<'_, [T]>> for Box<[T]> {
/// Converts a `Cow<'_, [T]>` into a `Box<[T]>`
///
/// When `cow` is the `Cow::Borrowed` variant, this
/// conversion allocates on the heap and copies the
/// underlying slice. Otherwise, it will try to reuse the owned
/// `Vec`'s allocation.
#[inline]
fn from(cow: Cow<'_, [T]>) -> Box<[T]> {
match cow {
Expand All @@ -1349,6 +1369,7 @@ impl From<&str> for Box<str> {
/// and performs a copy of `s`.
///
/// # Examples
///
/// ```rust
/// let boxed: Box<str> = Box::from("hello");
/// println!("{}", boxed);
Expand All @@ -1362,6 +1383,29 @@ impl From<&str> for Box<str> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_from_cow", since = "1.45.0")]
impl From<Cow<'_, str>> for Box<str> {
/// Converts a `Cow<'_, str>` into a `Box<str>`
///
/// When `cow` is the `Cow::Borrowed` variant, this
/// conversion allocates on the heap and copies the
/// underlying `str`. Otherwise, it will try to reuse the owned
/// `String`'s allocation.
///
/// # Examples
///
/// ```rust
/// use std::borrow::Cow;
///
/// let unboxed = Cow::Borrowed("hello");
/// let boxed: Box<str> = Box::from(unboxed);
/// println!("{}", boxed);
/// ```
///
/// ```rust
/// # use std::borrow::Cow;
/// let unboxed = Cow::Owned("hello".to_string());
/// let boxed: Box<str> = Box::from(unboxed);
/// println!("{}", boxed);
/// ```
#[inline]
fn from(cow: Cow<'_, str>) -> Box<str> {
match cow {
Expand Down Expand Up @@ -1396,13 +1440,15 @@ impl<A: Allocator> From<Box<str, A>> for Box<[u8], A> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_from_array", since = "1.45.0")]
impl<T, const N: usize> From<[T; N]> for Box<[T]> {
/// Converts a `[T; N]` into a `Box<[T]>`
///
/// This conversion moves the array to newly heap-allocated memory.
///
/// # Examples
///
/// ```rust
/// let boxed: Box<[u8]> = Box::from([4, 2]);
/// println!("{:?}", boxed);
Expand All @@ -1416,6 +1462,15 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
type Error = Box<[T]>;

/// Attempts to convert a `Box<[T]>` into a `Box<[T; N]>`.
///
/// The conversion occurs in-place and does not require a
/// new memory allocation.
///
/// # Errors
///
/// Returns the old `Box<[T]>` in the `Err` variant if
/// `boxed_slice.len()` does not equal `N`.
fn try_from(boxed_slice: Box<[T]>) -> Result<Self, Self::Error> {
if boxed_slice.len() == N {
Ok(unsafe { Box::from_raw(Box::into_raw(boxed_slice) as *mut [T; N]) })
Expand Down
47 changes: 47 additions & 0 deletions rust/alloc/collections/btree/dedup_sorted_iter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use core::iter::Peekable;

/// A iterator for deduping the key of a sorted iterator.
/// When encountering the duplicated key, only the last key-value pair is yielded.
///
/// Used by [`BTreeMap::bulk_build_from_sorted_iter`].
pub struct DedupSortedIter<K, V, I>
where
I: Iterator<Item = (K, V)>,
{
iter: Peekable<I>,
}

impl<K, V, I> DedupSortedIter<K, V, I>
where
I: Iterator<Item = (K, V)>,
{
pub fn new(iter: I) -> Self {
Self { iter: iter.peekable() }
}
}

impl<K, V, I> Iterator for DedupSortedIter<K, V, I>
where
K: Eq,
I: Iterator<Item = (K, V)>,
{
type Item = (K, V);

fn next(&mut self) -> Option<(K, V)> {
loop {
let next = match self.iter.next() {
Some(next) => next,
None => return None,
};

let peeked = match self.iter.peek() {
Some(peeked) => peeked,
None => return Some(next),
};

if next.0 != peeked.0 {
return Some(next);
}
}
}
}
4 changes: 2 additions & 2 deletions rust/alloc/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use core::fmt::Display;

/// The error type for `try_reserve` methods.
#[derive(Clone, PartialEq, Eq, Debug)]
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub struct TryReserveError {
kind: TryReserveErrorKind,
}
Expand Down Expand Up @@ -128,7 +128,7 @@ impl From<LayoutError> for TryReserveErrorKind {
}
}

#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
impl Display for TryReserveError {
fn fmt(
&self,
Expand Down
Loading