Skip to content

Commit 1155f18

Browse files
committed
Merge from rustc
2 parents 4cdaf51 + 2ad76d7 commit 1155f18

File tree

20 files changed

+190
-60
lines changed

20 files changed

+190
-60
lines changed

alloc/src/collections/btree/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,8 +3079,8 @@ impl<'a, K, V, A> CursorMut<'a, K, V, A> {
30793079
unsafe { self.root.reborrow() }
30803080
.as_mut()?
30813081
.borrow_mut()
3082-
.first_leaf_edge()
3083-
.next_kv()
3082+
.last_leaf_edge()
3083+
.next_back_kv()
30843084
.ok()?
30853085
.into_kv_valmut()
30863086
}

alloc/src/collections/btree/map/tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::testing::crash_test::{CrashTestDummy, Panic};
88
use crate::testing::ord_chaos::{Cyclic3, Governed, Governor};
99
use crate::testing::rng::DeterministicRng;
1010
use crate::vec::Vec;
11+
use core::assert_matches::assert_matches;
1112
use std::cmp::Ordering;
1213
use std::iter;
1314
use std::mem;
@@ -2448,3 +2449,21 @@ fn test_cursor_mut_insert_after_4() {
24482449
let mut cur = map.upper_bound_mut(Bound::Included(&2));
24492450
cur.insert_after(4, 'd');
24502451
}
2452+
2453+
#[test]
2454+
fn cursor_peek_prev_agrees_with_cursor_mut() {
2455+
let mut map = BTreeMap::from([(1, 1), (2, 2), (3, 3)]);
2456+
2457+
let cursor = map.lower_bound(Bound::Excluded(&3));
2458+
assert!(cursor.key().is_none());
2459+
2460+
let prev = cursor.peek_prev();
2461+
assert_matches!(prev, Some((&3, _)));
2462+
2463+
// Shadow names so the two parts of this test match.
2464+
let mut cursor = map.lower_bound_mut(Bound::Excluded(&3));
2465+
assert!(cursor.key().is_none());
2466+
2467+
let prev = cursor.peek_prev();
2468+
assert_matches!(prev, Some((&3, _)));
2469+
}

core/src/array/ascii.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@ use crate::ascii;
44
impl<const N: usize> [u8; N] {
55
/// Converts this array of bytes into a array of ASCII characters,
66
/// or returns `None` if any of the characters is non-ASCII.
7+
///
8+
/// # Examples
9+
///
10+
/// ```
11+
/// #![feature(ascii_char)]
12+
/// #![feature(const_option)]
13+
///
14+
/// const HEX_DIGITS: [std::ascii::Char; 16] =
15+
/// *b"0123456789abcdef".as_ascii().unwrap();
16+
///
17+
/// assert_eq!(HEX_DIGITS[1].as_str(), "1");
18+
/// assert_eq!(HEX_DIGITS[10].as_str(), "a");
19+
/// ```
720
#[unstable(feature = "ascii_char", issue = "110998")]
821
#[must_use]
922
#[inline]
10-
pub fn as_ascii(&self) -> Option<&[ascii::Char; N]> {
23+
pub const fn as_ascii(&self) -> Option<&[ascii::Char; N]> {
1124
if self.is_ascii() {
1225
// SAFETY: Just checked that it's ASCII
1326
Some(unsafe { self.as_ascii_unchecked() })

core/src/ffi/c_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ use crate::str;
7979
///
8080
/// [str]: prim@str "str"
8181
#[derive(Hash)]
82-
#[cfg_attr(not(test), rustc_diagnostic_item = "CStr")]
8382
#[stable(feature = "core_c_str", since = "1.64.0")]
8483
#[rustc_has_incoherent_inherent_impls]
84+
#[cfg_attr(not(bootstrap), lang = "CStr")]
8585
// FIXME:
8686
// `fn from` in `impl From<&CStr> for Box<CStr>` current implementation relies
8787
// on `CStr` being layout-compatible with `[u8]`.

core/src/iter/adapters/flatten.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ where
310310
/// Real logic of both `Flatten` and `FlatMap` which simply delegate to
311311
/// this type.
312312
#[derive(Clone, Debug)]
313+
#[unstable(feature = "trusted_len", issue = "37572")]
313314
struct FlattenCompat<I, U> {
314315
iter: Fuse<I>,
315316
frontiter: Option<U>,
@@ -463,6 +464,7 @@ where
463464
}
464465
}
465466

467+
#[unstable(feature = "trusted_len", issue = "37572")]
466468
impl<I, U> Iterator for FlattenCompat<I, U>
467469
where
468470
I: Iterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>,
@@ -577,6 +579,7 @@ where
577579
}
578580
}
579581

582+
#[unstable(feature = "trusted_len", issue = "37572")]
580583
impl<I, U> DoubleEndedIterator for FlattenCompat<I, U>
581584
where
582585
I: DoubleEndedIterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>,
@@ -646,20 +649,23 @@ where
646649
}
647650
}
648651

652+
#[unstable(feature = "trusted_len", issue = "37572")]
649653
unsafe impl<const N: usize, I, T> TrustedLen
650654
for FlattenCompat<I, <[T; N] as IntoIterator>::IntoIter>
651655
where
652656
I: TrustedLen<Item = [T; N]>,
653657
{
654658
}
655659

660+
#[unstable(feature = "trusted_len", issue = "37572")]
656661
unsafe impl<'a, const N: usize, I, T> TrustedLen
657662
for FlattenCompat<I, <&'a [T; N] as IntoIterator>::IntoIter>
658663
where
659664
I: TrustedLen<Item = &'a [T; N]>,
660665
{
661666
}
662667

668+
#[unstable(feature = "trusted_len", issue = "37572")]
663669
unsafe impl<'a, const N: usize, I, T> TrustedLen
664670
for FlattenCompat<I, <&'a mut [T; N] as IntoIterator>::IntoIter>
665671
where

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
#![feature(const_slice_from_raw_parts_mut)]
151151
#![feature(const_slice_from_ref)]
152152
#![feature(const_slice_index)]
153+
#![feature(const_slice_is_ascii)]
153154
#![feature(const_slice_ptr_len)]
154155
#![feature(const_slice_split_at_mut)]
155156
#![feature(const_str_from_utf8_unchecked_mut)]

core/src/mem/maybe_uninit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ impl<T, const N: usize> MaybeUninit<[T; N]> {
12871287
#[inline]
12881288
pub const fn transpose(self) -> [MaybeUninit<T>; N] {
12891289
// SAFETY: T and MaybeUninit<T> have the same layout
1290-
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
1290+
unsafe { intrinsics::transmute_unchecked(self) }
12911291
}
12921292
}
12931293

@@ -1307,6 +1307,6 @@ impl<T, const N: usize> [MaybeUninit<T>; N] {
13071307
#[inline]
13081308
pub const fn transpose(self) -> MaybeUninit<[T; N]> {
13091309
// SAFETY: T and MaybeUninit<T> have the same layout
1310-
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
1310+
unsafe { intrinsics::transmute_unchecked(self) }
13111311
}
13121312
}

core/src/net/socket_addr.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ impl SocketAddr {
122122
#[stable(feature = "ip_addr", since = "1.7.0")]
123123
#[must_use]
124124
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
125+
#[inline]
125126
pub const fn new(ip: IpAddr, port: u16) -> SocketAddr {
126127
match ip {
127128
IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)),
@@ -142,6 +143,7 @@ impl SocketAddr {
142143
#[must_use]
143144
#[stable(feature = "ip_addr", since = "1.7.0")]
144145
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
146+
#[inline]
145147
pub const fn ip(&self) -> IpAddr {
146148
match *self {
147149
SocketAddr::V4(ref a) => IpAddr::V4(*a.ip()),
@@ -161,6 +163,7 @@ impl SocketAddr {
161163
/// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1)));
162164
/// ```
163165
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
166+
#[inline]
164167
pub fn set_ip(&mut self, new_ip: IpAddr) {
165168
// `match (*self, new_ip)` would have us mutate a copy of self only to throw it away.
166169
match (self, new_ip) {
@@ -183,6 +186,7 @@ impl SocketAddr {
183186
#[must_use]
184187
#[stable(feature = "rust1", since = "1.0.0")]
185188
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
189+
#[inline]
186190
pub const fn port(&self) -> u16 {
187191
match *self {
188192
SocketAddr::V4(ref a) => a.port(),
@@ -202,6 +206,7 @@ impl SocketAddr {
202206
/// assert_eq!(socket.port(), 1025);
203207
/// ```
204208
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
209+
#[inline]
205210
pub fn set_port(&mut self, new_port: u16) {
206211
match *self {
207212
SocketAddr::V4(ref mut a) => a.set_port(new_port),
@@ -227,6 +232,7 @@ impl SocketAddr {
227232
#[must_use]
228233
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
229234
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
235+
#[inline]
230236
pub const fn is_ipv4(&self) -> bool {
231237
matches!(*self, SocketAddr::V4(_))
232238
}
@@ -249,6 +255,7 @@ impl SocketAddr {
249255
#[must_use]
250256
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
251257
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
258+
#[inline]
252259
pub const fn is_ipv6(&self) -> bool {
253260
matches!(*self, SocketAddr::V6(_))
254261
}
@@ -269,6 +276,7 @@ impl SocketAddrV4 {
269276
#[stable(feature = "rust1", since = "1.0.0")]
270277
#[must_use]
271278
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
279+
#[inline]
272280
pub const fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 {
273281
SocketAddrV4 { ip, port }
274282
}
@@ -286,6 +294,7 @@ impl SocketAddrV4 {
286294
#[must_use]
287295
#[stable(feature = "rust1", since = "1.0.0")]
288296
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
297+
#[inline]
289298
pub const fn ip(&self) -> &Ipv4Addr {
290299
&self.ip
291300
}
@@ -302,6 +311,7 @@ impl SocketAddrV4 {
302311
/// assert_eq!(socket.ip(), &Ipv4Addr::new(192, 168, 0, 1));
303312
/// ```
304313
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
314+
#[inline]
305315
pub fn set_ip(&mut self, new_ip: Ipv4Addr) {
306316
self.ip = new_ip;
307317
}
@@ -319,6 +329,7 @@ impl SocketAddrV4 {
319329
#[must_use]
320330
#[stable(feature = "rust1", since = "1.0.0")]
321331
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
332+
#[inline]
322333
pub const fn port(&self) -> u16 {
323334
self.port
324335
}
@@ -335,6 +346,7 @@ impl SocketAddrV4 {
335346
/// assert_eq!(socket.port(), 4242);
336347
/// ```
337348
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
349+
#[inline]
338350
pub fn set_port(&mut self, new_port: u16) {
339351
self.port = new_port;
340352
}
@@ -360,6 +372,7 @@ impl SocketAddrV6 {
360372
#[stable(feature = "rust1", since = "1.0.0")]
361373
#[must_use]
362374
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
375+
#[inline]
363376
pub const fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 {
364377
SocketAddrV6 { ip, port, flowinfo, scope_id }
365378
}
@@ -377,6 +390,7 @@ impl SocketAddrV6 {
377390
#[must_use]
378391
#[stable(feature = "rust1", since = "1.0.0")]
379392
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
393+
#[inline]
380394
pub const fn ip(&self) -> &Ipv6Addr {
381395
&self.ip
382396
}
@@ -393,6 +407,7 @@ impl SocketAddrV6 {
393407
/// assert_eq!(socket.ip(), &Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0));
394408
/// ```
395409
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
410+
#[inline]
396411
pub fn set_ip(&mut self, new_ip: Ipv6Addr) {
397412
self.ip = new_ip;
398413
}
@@ -410,6 +425,7 @@ impl SocketAddrV6 {
410425
#[must_use]
411426
#[stable(feature = "rust1", since = "1.0.0")]
412427
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
428+
#[inline]
413429
pub const fn port(&self) -> u16 {
414430
self.port
415431
}
@@ -426,6 +442,7 @@ impl SocketAddrV6 {
426442
/// assert_eq!(socket.port(), 4242);
427443
/// ```
428444
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
445+
#[inline]
429446
pub fn set_port(&mut self, new_port: u16) {
430447
self.port = new_port;
431448
}
@@ -453,6 +470,7 @@ impl SocketAddrV6 {
453470
#[must_use]
454471
#[stable(feature = "rust1", since = "1.0.0")]
455472
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
473+
#[inline]
456474
pub const fn flowinfo(&self) -> u32 {
457475
self.flowinfo
458476
}
@@ -471,6 +489,7 @@ impl SocketAddrV6 {
471489
/// assert_eq!(socket.flowinfo(), 56);
472490
/// ```
473491
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
492+
#[inline]
474493
pub fn set_flowinfo(&mut self, new_flowinfo: u32) {
475494
self.flowinfo = new_flowinfo;
476495
}
@@ -493,6 +512,7 @@ impl SocketAddrV6 {
493512
#[must_use]
494513
#[stable(feature = "rust1", since = "1.0.0")]
495514
#[rustc_const_stable(feature = "const_socketaddr", since = "1.69.0")]
515+
#[inline]
496516
pub const fn scope_id(&self) -> u32 {
497517
self.scope_id
498518
}
@@ -511,6 +531,7 @@ impl SocketAddrV6 {
511531
/// assert_eq!(socket.scope_id(), 42);
512532
/// ```
513533
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
534+
#[inline]
514535
pub fn set_scope_id(&mut self, new_scope_id: u32) {
515536
self.scope_id = new_scope_id;
516537
}
@@ -519,6 +540,7 @@ impl SocketAddrV6 {
519540
#[stable(feature = "ip_from_ip", since = "1.16.0")]
520541
impl From<SocketAddrV4> for SocketAddr {
521542
/// Converts a [`SocketAddrV4`] into a [`SocketAddr::V4`].
543+
#[inline]
522544
fn from(sock4: SocketAddrV4) -> SocketAddr {
523545
SocketAddr::V4(sock4)
524546
}
@@ -527,6 +549,7 @@ impl From<SocketAddrV4> for SocketAddr {
527549
#[stable(feature = "ip_from_ip", since = "1.16.0")]
528550
impl From<SocketAddrV6> for SocketAddr {
529551
/// Converts a [`SocketAddrV6`] into a [`SocketAddr::V6`].
552+
#[inline]
530553
fn from(sock6: SocketAddrV6) -> SocketAddr {
531554
SocketAddr::V6(sock6)
532555
}
@@ -624,27 +647,31 @@ impl fmt::Debug for SocketAddrV6 {
624647

625648
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
626649
impl PartialOrd for SocketAddrV4 {
650+
#[inline]
627651
fn partial_cmp(&self, other: &SocketAddrV4) -> Option<Ordering> {
628652
Some(self.cmp(other))
629653
}
630654
}
631655

632656
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
633657
impl PartialOrd for SocketAddrV6 {
658+
#[inline]
634659
fn partial_cmp(&self, other: &SocketAddrV6) -> Option<Ordering> {
635660
Some(self.cmp(other))
636661
}
637662
}
638663

639664
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
640665
impl Ord for SocketAddrV4 {
666+
#[inline]
641667
fn cmp(&self, other: &SocketAddrV4) -> Ordering {
642668
self.ip().cmp(other.ip()).then(self.port().cmp(&other.port()))
643669
}
644670
}
645671

646672
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
647673
impl Ord for SocketAddrV6 {
674+
#[inline]
648675
fn cmp(&self, other: &SocketAddrV6) -> Ordering {
649676
self.ip().cmp(other.ip()).then(self.port().cmp(&other.port()))
650677
}

core/src/option.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,10 +1641,8 @@ impl<T> Option<T> {
16411641
where
16421642
F: FnOnce() -> T,
16431643
{
1644-
if let None = *self {
1645-
// the compiler isn't smart enough to know that we are not dropping a `T`
1646-
// here and wants us to ensure `T` can be dropped at compile time.
1647-
mem::forget(mem::replace(self, Some(f())))
1644+
if let None = self {
1645+
*self = Some(f());
16481646
}
16491647

16501648
// SAFETY: a `None` variant for `self` would have been replaced by a `Some`

0 commit comments

Comments
 (0)