Skip to content

Commit 090949b

Browse files
authored
Merge pull request rust-lang#1889 from rust-lang/rustc-pull
Rustc pull update
2 parents cde9c62 + 1bfa106 commit 090949b

File tree

81 files changed

+1814
-909
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1814
-909
lines changed

Cargo.lock

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

alloc/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ compiler_builtins = { path = "../compiler-builtins/compiler-builtins", features
2121
[features]
2222
compiler-builtins-mem = ['compiler_builtins/mem']
2323
compiler-builtins-c = ["compiler_builtins/c"]
24-
compiler-builtins-no-asm = ["compiler_builtins/no-asm"]
2524
compiler-builtins-no-f16-f128 = ["compiler_builtins/no-f16-f128"]
26-
compiler-builtins-mangled-names = ["compiler_builtins/mangled-names"]
2725
# Make panics and failed asserts immediately abort without formatting any message
2826
panic_immediate_abort = ["core/panic_immediate_abort"]
2927
# Choose algorithms that are optimized for binary size instead of runtime performance

alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
// tidy-alphabetical-start
9595
#![feature(alloc_layout_extra)]
9696
#![feature(allocator_api)]
97-
#![feature(array_chunks)]
9897
#![feature(array_into_iter_constructors)]
9998
#![feature(array_windows)]
10099
#![feature(ascii_char)]

alloc/src/slice.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ use core::cmp::Ordering::{self, Less};
1616
use core::mem::MaybeUninit;
1717
#[cfg(not(no_global_oom_handling))]
1818
use core::ptr;
19-
#[unstable(feature = "array_chunks", issue = "74985")]
20-
pub use core::slice::ArrayChunks;
21-
#[unstable(feature = "array_chunks", issue = "74985")]
22-
pub use core::slice::ArrayChunksMut;
2319
#[unstable(feature = "array_windows", issue = "75027")]
2420
pub use core::slice::ArrayWindows;
2521
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")]

alloc/src/string.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -787,12 +787,12 @@ impl String {
787787
#[cfg(not(no_global_oom_handling))]
788788
#[unstable(feature = "str_from_utf16_endian", issue = "116258")]
789789
pub fn from_utf16le(v: &[u8]) -> Result<String, FromUtf16Error> {
790-
if v.len() % 2 != 0 {
790+
let (chunks, []) = v.as_chunks::<2>() else {
791791
return Err(FromUtf16Error(()));
792-
}
792+
};
793793
match (cfg!(target_endian = "little"), unsafe { v.align_to::<u16>() }) {
794794
(true, ([], v, [])) => Self::from_utf16(v),
795-
_ => char::decode_utf16(v.array_chunks::<2>().copied().map(u16::from_le_bytes))
795+
_ => char::decode_utf16(chunks.iter().copied().map(u16::from_le_bytes))
796796
.collect::<Result<_, _>>()
797797
.map_err(|_| FromUtf16Error(())),
798798
}
@@ -830,11 +830,11 @@ impl String {
830830
(true, ([], v, [])) => Self::from_utf16_lossy(v),
831831
(true, ([], v, [_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
832832
_ => {
833-
let mut iter = v.array_chunks::<2>();
834-
let string = char::decode_utf16(iter.by_ref().copied().map(u16::from_le_bytes))
833+
let (chunks, remainder) = v.as_chunks::<2>();
834+
let string = char::decode_utf16(chunks.iter().copied().map(u16::from_le_bytes))
835835
.map(|r| r.unwrap_or(char::REPLACEMENT_CHARACTER))
836836
.collect();
837-
if iter.remainder().is_empty() { string } else { string + "\u{FFFD}" }
837+
if remainder.is_empty() { string } else { string + "\u{FFFD}" }
838838
}
839839
}
840840
}
@@ -862,12 +862,12 @@ impl String {
862862
#[cfg(not(no_global_oom_handling))]
863863
#[unstable(feature = "str_from_utf16_endian", issue = "116258")]
864864
pub fn from_utf16be(v: &[u8]) -> Result<String, FromUtf16Error> {
865-
if v.len() % 2 != 0 {
865+
let (chunks, []) = v.as_chunks::<2>() else {
866866
return Err(FromUtf16Error(()));
867-
}
867+
};
868868
match (cfg!(target_endian = "big"), unsafe { v.align_to::<u16>() }) {
869869
(true, ([], v, [])) => Self::from_utf16(v),
870-
_ => char::decode_utf16(v.array_chunks::<2>().copied().map(u16::from_be_bytes))
870+
_ => char::decode_utf16(chunks.iter().copied().map(u16::from_be_bytes))
871871
.collect::<Result<_, _>>()
872872
.map_err(|_| FromUtf16Error(())),
873873
}
@@ -905,11 +905,11 @@ impl String {
905905
(true, ([], v, [])) => Self::from_utf16_lossy(v),
906906
(true, ([], v, [_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
907907
_ => {
908-
let mut iter = v.array_chunks::<2>();
909-
let string = char::decode_utf16(iter.by_ref().copied().map(u16::from_be_bytes))
908+
let (chunks, remainder) = v.as_chunks::<2>();
909+
let string = char::decode_utf16(chunks.iter().copied().map(u16::from_be_bytes))
910910
.map(|r| r.unwrap_or(char::REPLACEMENT_CHARACTER))
911911
.collect();
912-
if iter.remainder().is_empty() { string } else { string + "\u{FFFD}" }
912+
if remainder.is_empty() { string } else { string + "\u{FFFD}" }
913913
}
914914
}
915915
}

core/src/borrow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,20 @@ impl<T: ?Sized> BorrowMut<T> for T {
223223
#[stable(feature = "rust1", since = "1.0.0")]
224224
impl<T: ?Sized> Borrow<T> for &T {
225225
fn borrow(&self) -> &T {
226-
&**self
226+
self
227227
}
228228
}
229229

230230
#[stable(feature = "rust1", since = "1.0.0")]
231231
impl<T: ?Sized> Borrow<T> for &mut T {
232232
fn borrow(&self) -> &T {
233-
&**self
233+
self
234234
}
235235
}
236236

237237
#[stable(feature = "rust1", since = "1.0.0")]
238238
impl<T: ?Sized> BorrowMut<T> for &mut T {
239239
fn borrow_mut(&mut self) -> &mut T {
240-
&mut **self
240+
self
241241
}
242242
}

core/src/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ mod impls {
590590
#[inline(always)]
591591
#[rustc_diagnostic_item = "noop_method_clone"]
592592
fn clone(&self) -> Self {
593-
*self
593+
self
594594
}
595595
}
596596

core/src/iter/adapters/rev.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ impl<T> Rev<T> {
2020
pub(in crate::iter) fn new(iter: T) -> Rev<T> {
2121
Rev { iter }
2222
}
23+
24+
/// Consumes the `Rev`, returning the inner iterator.
25+
///
26+
/// # Examples
27+
///
28+
/// ```rust
29+
/// #![feature(rev_into_inner)]
30+
///
31+
/// let s = "foobar";
32+
/// let mut rev = s.chars().rev();
33+
/// assert_eq!(rev.next(), Some('r'));
34+
/// assert_eq!(rev.next(), Some('a'));
35+
/// assert_eq!(rev.next(), Some('b'));
36+
/// assert_eq!(rev.into_inner().collect::<String>(), "foo");
37+
/// ```
38+
#[unstable(feature = "rev_into_inner", issue = "144277")]
39+
pub fn into_inner(self) -> T {
40+
self.iter
41+
}
2342
}
2443

2544
#[stable(feature = "rust1", since = "1.0.0")]

core/src/macros/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,10 @@ pub macro debug_assert_matches($($arg:tt)*) {
426426
#[macro_export]
427427
#[stable(feature = "matches_macro", since = "1.42.0")]
428428
#[rustc_diagnostic_item = "matches_macro"]
429+
#[allow_internal_unstable(non_exhaustive_omitted_patterns_lint, stmt_expr_attributes)]
429430
macro_rules! matches {
430431
($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => {
432+
#[allow(non_exhaustive_omitted_patterns)]
431433
match $expression {
432434
$pattern $(if $guard)? => true,
433435
_ => false

core/src/mem/drop_guard.rs

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
use crate::fmt::{self, Debug};
2+
use crate::mem::ManuallyDrop;
3+
use crate::ops::{Deref, DerefMut};
4+
5+
/// Wrap a value and run a closure when dropped.
6+
///
7+
/// This is useful for quickly creating destructors inline.
8+
///
9+
/// # Examples
10+
///
11+
/// ```rust
12+
/// # #![allow(unused)]
13+
/// #![feature(drop_guard)]
14+
///
15+
/// use std::mem::DropGuard;
16+
///
17+
/// {
18+
/// // Create a new guard around a string that will
19+
/// // print its value when dropped.
20+
/// let s = String::from("Chashu likes tuna");
21+
/// let mut s = DropGuard::new(s, |s| println!("{s}"));
22+
///
23+
/// // Modify the string contained in the guard.
24+
/// s.push_str("!!!");
25+
///
26+
/// // The guard will be dropped here, printing:
27+
/// // "Chashu likes tuna!!!"
28+
/// }
29+
/// ```
30+
#[unstable(feature = "drop_guard", issue = "144426")]
31+
#[doc(alias = "ScopeGuard")]
32+
#[doc(alias = "defer")]
33+
pub struct DropGuard<T, F>
34+
where
35+
F: FnOnce(T),
36+
{
37+
inner: ManuallyDrop<T>,
38+
f: ManuallyDrop<F>,
39+
}
40+
41+
impl<T, F> DropGuard<T, F>
42+
where
43+
F: FnOnce(T),
44+
{
45+
/// Create a new instance of `DropGuard`.
46+
///
47+
/// # Example
48+
///
49+
/// ```rust
50+
/// # #![allow(unused)]
51+
/// #![feature(drop_guard)]
52+
///
53+
/// use std::mem::DropGuard;
54+
///
55+
/// let value = String::from("Chashu likes tuna");
56+
/// let guard = DropGuard::new(value, |s| println!("{s}"));
57+
/// ```
58+
#[unstable(feature = "drop_guard", issue = "144426")]
59+
#[must_use]
60+
pub const fn new(inner: T, f: F) -> Self {
61+
Self { inner: ManuallyDrop::new(inner), f: ManuallyDrop::new(f) }
62+
}
63+
64+
/// Consumes the `DropGuard`, returning the wrapped value.
65+
///
66+
/// This will not execute the closure. This is implemented as an associated
67+
/// function to prevent any potential conflicts with any other methods called
68+
/// `into_inner` from the `Deref` and `DerefMut` impls.
69+
///
70+
/// It is typically preferred to call this function instead of `mem::forget`
71+
/// because it will return the stored value and drop variables captured
72+
/// by the closure instead of leaking their owned resources.
73+
///
74+
/// # Example
75+
///
76+
/// ```rust
77+
/// # #![allow(unused)]
78+
/// #![feature(drop_guard)]
79+
///
80+
/// use std::mem::DropGuard;
81+
///
82+
/// let value = String::from("Nori likes chicken");
83+
/// let guard = DropGuard::new(value, |s| println!("{s}"));
84+
/// assert_eq!(DropGuard::into_inner(guard), "Nori likes chicken");
85+
/// ```
86+
#[unstable(feature = "drop_guard", issue = "144426")]
87+
#[inline]
88+
pub fn into_inner(guard: Self) -> T {
89+
// First we ensure that dropping the guard will not trigger
90+
// its destructor
91+
let mut guard = ManuallyDrop::new(guard);
92+
93+
// Next we manually read the stored value from the guard.
94+
//
95+
// SAFETY: this is safe because we've taken ownership of the guard.
96+
let value = unsafe { ManuallyDrop::take(&mut guard.inner) };
97+
98+
// Finally we drop the stored closure. We do this *after* having read
99+
// the value, so that even if the closure's `drop` function panics,
100+
// unwinding still tries to drop the value.
101+
//
102+
// SAFETY: this is safe because we've taken ownership of the guard.
103+
unsafe { ManuallyDrop::drop(&mut guard.f) };
104+
value
105+
}
106+
}
107+
108+
#[unstable(feature = "drop_guard", issue = "144426")]
109+
impl<T, F> Deref for DropGuard<T, F>
110+
where
111+
F: FnOnce(T),
112+
{
113+
type Target = T;
114+
115+
fn deref(&self) -> &T {
116+
&*self.inner
117+
}
118+
}
119+
120+
#[unstable(feature = "drop_guard", issue = "144426")]
121+
impl<T, F> DerefMut for DropGuard<T, F>
122+
where
123+
F: FnOnce(T),
124+
{
125+
fn deref_mut(&mut self) -> &mut T {
126+
&mut *self.inner
127+
}
128+
}
129+
130+
#[unstable(feature = "drop_guard", issue = "144426")]
131+
impl<T, F> Drop for DropGuard<T, F>
132+
where
133+
F: FnOnce(T),
134+
{
135+
fn drop(&mut self) {
136+
// SAFETY: `DropGuard` is in the process of being dropped.
137+
let inner = unsafe { ManuallyDrop::take(&mut self.inner) };
138+
139+
// SAFETY: `DropGuard` is in the process of being dropped.
140+
let f = unsafe { ManuallyDrop::take(&mut self.f) };
141+
142+
f(inner);
143+
}
144+
}
145+
146+
#[unstable(feature = "drop_guard", issue = "144426")]
147+
impl<T, F> Debug for DropGuard<T, F>
148+
where
149+
T: Debug,
150+
F: FnOnce(T),
151+
{
152+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153+
fmt::Debug::fmt(&**self, f)
154+
}
155+
}

0 commit comments

Comments
 (0)