Skip to content

Commit cfeaf05

Browse files
authored
Merge pull request torvalds#586 from ojeda/rust-1.57
Rust 1.57
2 parents a3fb8b8 + 3e70537 commit cfeaf05

25 files changed

+335
-159
lines changed

.github/workflows/ci.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
arch: [arm, arm64, ppc64le, riscv64, x86_64]
1414
toolchain: [gcc, clang, llvm]
1515
config: [debug, release]
16-
rustc: [1.56.0]
16+
rustc: [1.57.0]
1717
output: [src] # [src, build]
1818
install: [rustup] # [rustup, standalone]
1919
sysroot: [common] # [common, custom]
@@ -49,7 +49,7 @@ jobs:
4949
- arch: arm64
5050
toolchain: gcc
5151
config: debug
52-
rustc: 1.56.0
52+
rustc: 1.57.0
5353
output: build
5454
install: rustup
5555
sysroot: custom
@@ -58,7 +58,7 @@ jobs:
5858
- arch: arm64
5959
toolchain: llvm
6060
config: debug
61-
rustc: 1.56.0
61+
rustc: 1.57.0
6262
output: build
6363
install: rustup
6464
sysroot: custom
@@ -67,7 +67,7 @@ jobs:
6767
- arch: arm64
6868
toolchain: llvm
6969
config: release
70-
rustc: 1.56.0
70+
rustc: 1.57.0
7171
output: build
7272
install: rustup
7373
sysroot: custom
@@ -76,7 +76,7 @@ jobs:
7676
- arch: ppc64le
7777
toolchain: clang
7878
config: release
79-
rustc: 1.56.0
79+
rustc: 1.57.0
8080
output: build
8181
install: standalone
8282
sysroot: common
@@ -85,7 +85,7 @@ jobs:
8585
- arch: x86_64
8686
toolchain: llvm
8787
config: debug
88-
rustc: 1.56.0
88+
rustc: 1.57.0
8989
output: build
9090
install: standalone
9191
sysroot: custom
@@ -94,7 +94,7 @@ jobs:
9494
- arch: x86_64
9595
toolchain: llvm
9696
config: debug
97-
rustc: 1.56.0
97+
rustc: 1.57.0
9898
output: src
9999
install: rustup
100100
sysroot: common
@@ -103,7 +103,7 @@ jobs:
103103
- arch: x86_64
104104
toolchain: llvm
105105
config: release
106-
rustc: 1.56.0
106+
rustc: 1.57.0
107107
output: src
108108
install: rustup
109109
sysroot: common

Documentation/process/changes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ know what you are doing, use the exact version listed here. Please see
3636
====================== =============== ========================================
3737
GNU C 5.1 gcc --version
3838
Clang/LLVM (optional) 10.0.1 clang --version
39-
rustc (optional) 1.56.0 rustc --version
39+
rustc (optional) 1.57.0 rustc --version
4040
bindgen (optional) 0.56.0 bindgen --version
4141
GNU make 3.81 make --version
4242
binutils 2.23 ld -v

Documentation/rust/quick-start.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Rust features.
2626
If ``rustup`` is being used, enter the checked out source code directory
2727
and run::
2828

29-
rustup override set 1.56.0
29+
rustup override set 1.57.0
3030

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

drivers/android/rust_binder.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
//! TODO: This module is a work in progress.
66
77
#![no_std]
8-
#![feature(
9-
global_asm,
10-
try_reserve,
11-
allocator_api,
12-
concat_idents,
13-
generic_associated_types
14-
)]
8+
#![feature(global_asm, allocator_api, concat_idents, generic_associated_types)]
159

1610
use kernel::{
1711
io_buffer::IoBufferWriter,

rust/alloc/alloc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ unsafe impl Allocator for Global {
309309
}
310310

311311
/// The allocator for unique pointers.
312-
// This function must not unwind. If it does, MIR codegen will fail.
313312
#[cfg(all(not(no_global_oom_handling), not(test)))]
314313
#[lang = "exchange_malloc"]
315314
#[inline]

rust/alloc/borrow.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
332332
}
333333

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

338342
fn deref(&self) -> &B {

rust/alloc/boxed.rs

+55
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl<T> Box<T> {
189189
#[cfg(not(no_global_oom_handling))]
190190
#[inline(always)]
191191
#[stable(feature = "rust1", since = "1.0.0")]
192+
#[must_use]
192193
pub fn new(x: T) -> Self {
193194
box x
194195
}
@@ -213,6 +214,7 @@ impl<T> Box<T> {
213214
/// ```
214215
#[cfg(not(no_global_oom_handling))]
215216
#[unstable(feature = "new_uninit", issue = "63291")]
217+
#[must_use]
216218
#[inline]
217219
pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
218220
Self::new_uninit_in(Global)
@@ -239,6 +241,7 @@ impl<T> Box<T> {
239241
#[cfg(not(no_global_oom_handling))]
240242
#[inline]
241243
#[unstable(feature = "new_uninit", issue = "63291")]
244+
#[must_use]
242245
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
243246
Self::new_zeroed_in(Global)
244247
}
@@ -247,6 +250,7 @@ impl<T> Box<T> {
247250
/// `x` will be pinned in memory and unable to be moved.
248251
#[cfg(not(no_global_oom_handling))]
249252
#[stable(feature = "pin", since = "1.33.0")]
253+
#[must_use]
250254
#[inline(always)]
251255
pub fn pin(x: T) -> Pin<Box<T>> {
252256
(box x).into()
@@ -341,6 +345,7 @@ impl<T, A: Allocator> Box<T, A> {
341345
/// ```
342346
#[cfg(not(no_global_oom_handling))]
343347
#[unstable(feature = "allocator_api", issue = "32838")]
348+
#[must_use]
344349
#[inline]
345350
pub fn new_in(x: T, alloc: A) -> Self {
346351
let mut boxed = Self::new_uninit_in(alloc);
@@ -397,6 +402,7 @@ impl<T, A: Allocator> Box<T, A> {
397402
/// ```
398403
#[unstable(feature = "allocator_api", issue = "32838")]
399404
#[cfg(not(no_global_oom_handling))]
405+
#[must_use]
400406
// #[unstable(feature = "new_uninit", issue = "63291")]
401407
pub fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> {
402408
let layout = Layout::new::<mem::MaybeUninit<T>>();
@@ -461,6 +467,7 @@ impl<T, A: Allocator> Box<T, A> {
461467
#[unstable(feature = "allocator_api", issue = "32838")]
462468
#[cfg(not(no_global_oom_handling))]
463469
// #[unstable(feature = "new_uninit", issue = "63291")]
470+
#[must_use]
464471
pub fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> {
465472
let layout = Layout::new::<mem::MaybeUninit<T>>();
466473
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -505,6 +512,7 @@ impl<T, A: Allocator> Box<T, A> {
505512
/// `x` will be pinned in memory and unable to be moved.
506513
#[cfg(not(no_global_oom_handling))]
507514
#[unstable(feature = "allocator_api", issue = "32838")]
515+
#[must_use]
508516
#[inline(always)]
509517
pub fn pin_in(x: T, alloc: A) -> Pin<Self>
510518
where
@@ -563,6 +571,7 @@ impl<T> Box<[T]> {
563571
/// ```
564572
#[cfg(not(no_global_oom_handling))]
565573
#[unstable(feature = "new_uninit", issue = "63291")]
574+
#[must_use]
566575
pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
567576
unsafe { RawVec::with_capacity(len).into_box(len) }
568577
}
@@ -587,6 +596,7 @@ impl<T> Box<[T]> {
587596
/// [zeroed]: mem::MaybeUninit::zeroed
588597
#[cfg(not(no_global_oom_handling))]
589598
#[unstable(feature = "new_uninit", issue = "63291")]
599+
#[must_use]
590600
pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
591601
unsafe { RawVec::with_capacity_zeroed(len).into_box(len) }
592602
}
@@ -683,6 +693,7 @@ impl<T, A: Allocator> Box<[T], A> {
683693
#[cfg(not(no_global_oom_handling))]
684694
#[unstable(feature = "allocator_api", issue = "32838")]
685695
// #[unstable(feature = "new_uninit", issue = "63291")]
696+
#[must_use]
686697
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
687698
unsafe { RawVec::with_capacity_in(len, alloc).into_box(len) }
688699
}
@@ -710,6 +721,7 @@ impl<T, A: Allocator> Box<[T], A> {
710721
#[cfg(not(no_global_oom_handling))]
711722
#[unstable(feature = "allocator_api", issue = "32838")]
712723
// #[unstable(feature = "new_uninit", issue = "63291")]
724+
#[must_use]
713725
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
714726
unsafe { RawVec::with_capacity_zeroed_in(len, alloc).into_box(len) }
715727
}
@@ -1088,6 +1100,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
10881100
}
10891101
}
10901102

1103+
#[cfg(not(no_global_oom_handling))]
10911104
#[stable(feature = "rust1", since = "1.0.0")]
10921105
impl<T: Default> Default for Box<T> {
10931106
/// Creates a `Box<T>`, with the `Default` value for T.
@@ -1278,6 +1291,7 @@ impl<T> From<T> for Box<T> {
12781291
/// from the stack into it.
12791292
///
12801293
/// # Examples
1294+
///
12811295
/// ```rust
12821296
/// let x = 5;
12831297
/// let boxed = Box::new(5);
@@ -1331,6 +1345,12 @@ impl<T: Copy> From<&[T]> for Box<[T]> {
13311345
#[cfg(not(no_global_oom_handling))]
13321346
#[stable(feature = "box_from_cow", since = "1.45.0")]
13331347
impl<T: Copy> From<Cow<'_, [T]>> for Box<[T]> {
1348+
/// Converts a `Cow<'_, [T]>` into a `Box<[T]>`
1349+
///
1350+
/// When `cow` is the `Cow::Borrowed` variant, this
1351+
/// conversion allocates on the heap and copies the
1352+
/// underlying slice. Otherwise, it will try to reuse the owned
1353+
/// `Vec`'s allocation.
13341354
#[inline]
13351355
fn from(cow: Cow<'_, [T]>) -> Box<[T]> {
13361356
match cow {
@@ -1349,6 +1369,7 @@ impl From<&str> for Box<str> {
13491369
/// and performs a copy of `s`.
13501370
///
13511371
/// # Examples
1372+
///
13521373
/// ```rust
13531374
/// let boxed: Box<str> = Box::from("hello");
13541375
/// println!("{}", boxed);
@@ -1362,6 +1383,29 @@ impl From<&str> for Box<str> {
13621383
#[cfg(not(no_global_oom_handling))]
13631384
#[stable(feature = "box_from_cow", since = "1.45.0")]
13641385
impl From<Cow<'_, str>> for Box<str> {
1386+
/// Converts a `Cow<'_, str>` into a `Box<str>`
1387+
///
1388+
/// When `cow` is the `Cow::Borrowed` variant, this
1389+
/// conversion allocates on the heap and copies the
1390+
/// underlying `str`. Otherwise, it will try to reuse the owned
1391+
/// `String`'s allocation.
1392+
///
1393+
/// # Examples
1394+
///
1395+
/// ```rust
1396+
/// use std::borrow::Cow;
1397+
///
1398+
/// let unboxed = Cow::Borrowed("hello");
1399+
/// let boxed: Box<str> = Box::from(unboxed);
1400+
/// println!("{}", boxed);
1401+
/// ```
1402+
///
1403+
/// ```rust
1404+
/// # use std::borrow::Cow;
1405+
/// let unboxed = Cow::Owned("hello".to_string());
1406+
/// let boxed: Box<str> = Box::from(unboxed);
1407+
/// println!("{}", boxed);
1408+
/// ```
13651409
#[inline]
13661410
fn from(cow: Cow<'_, str>) -> Box<str> {
13671411
match cow {
@@ -1396,13 +1440,15 @@ impl<A: Allocator> From<Box<str, A>> for Box<[u8], A> {
13961440
}
13971441
}
13981442

1443+
#[cfg(not(no_global_oom_handling))]
13991444
#[stable(feature = "box_from_array", since = "1.45.0")]
14001445
impl<T, const N: usize> From<[T; N]> for Box<[T]> {
14011446
/// Converts a `[T; N]` into a `Box<[T]>`
14021447
///
14031448
/// This conversion moves the array to newly heap-allocated memory.
14041449
///
14051450
/// # Examples
1451+
///
14061452
/// ```rust
14071453
/// let boxed: Box<[u8]> = Box::from([4, 2]);
14081454
/// println!("{:?}", boxed);
@@ -1416,6 +1462,15 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
14161462
impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
14171463
type Error = Box<[T]>;
14181464

1465+
/// Attempts to convert a `Box<[T]>` into a `Box<[T; N]>`.
1466+
///
1467+
/// The conversion occurs in-place and does not require a
1468+
/// new memory allocation.
1469+
///
1470+
/// # Errors
1471+
///
1472+
/// Returns the old `Box<[T]>` in the `Err` variant if
1473+
/// `boxed_slice.len()` does not equal `N`.
14191474
fn try_from(boxed_slice: Box<[T]>) -> Result<Self, Self::Error> {
14201475
if boxed_slice.len() == N {
14211476
Ok(unsafe { Box::from_raw(Box::into_raw(boxed_slice) as *mut [T; N]) })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use core::iter::Peekable;
2+
3+
/// A iterator for deduping the key of a sorted iterator.
4+
/// When encountering the duplicated key, only the last key-value pair is yielded.
5+
///
6+
/// Used by [`BTreeMap::bulk_build_from_sorted_iter`].
7+
pub struct DedupSortedIter<K, V, I>
8+
where
9+
I: Iterator<Item = (K, V)>,
10+
{
11+
iter: Peekable<I>,
12+
}
13+
14+
impl<K, V, I> DedupSortedIter<K, V, I>
15+
where
16+
I: Iterator<Item = (K, V)>,
17+
{
18+
pub fn new(iter: I) -> Self {
19+
Self { iter: iter.peekable() }
20+
}
21+
}
22+
23+
impl<K, V, I> Iterator for DedupSortedIter<K, V, I>
24+
where
25+
K: Eq,
26+
I: Iterator<Item = (K, V)>,
27+
{
28+
type Item = (K, V);
29+
30+
fn next(&mut self) -> Option<(K, V)> {
31+
loop {
32+
let next = match self.iter.next() {
33+
Some(next) => next,
34+
None => return None,
35+
};
36+
37+
let peeked = match self.iter.peek() {
38+
Some(peeked) => peeked,
39+
None => return Some(next),
40+
};
41+
42+
if next.0 != peeked.0 {
43+
return Some(next);
44+
}
45+
}
46+
}
47+
}

rust/alloc/collections/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use core::fmt::Display;
5959

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

131-
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
131+
#[stable(feature = "try_reserve", since = "1.57.0")]
132132
impl Display for TryReserveError {
133133
fn fmt(
134134
&self,

0 commit comments

Comments
 (0)