Skip to content

Commit a09b495

Browse files
committed
Auto merge of #89512 - Manishearth:rollup-meh9x7r, r=Manishearth
Rollup of 14 pull requests Successful merges: - #86434 (Add `Ipv6Addr::is_benchmarking`) - #86828 (const fn for option copied, take & replace) - #87679 (BTree: refine some comments) - #87910 (Mark unsafe methods NonZero*::unchecked_(add|mul) as const.) - #88286 (Remove unnecessary unsafe block in `process_unix`) - #88305 (Manual Debug for Unix ExitCode ExitStatus ExitStatusError) - #88353 (Partially stabilize `array_methods`) - #88370 (Add missing `# Panics` section to `Vec` method) - #88481 (Remove some feature gates) - #89138 (Fix link in Ipv6Addr::to_ipv4 docs) - #89401 (Add truncate note to Vec::resize) - #89467 (Fix typos in rustdoc/lints) - #89472 (Only register `WSACleanup` if `WSAStartup` is actually ever called) - #89505 (Add regression test for spurious const error with NLL) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6adb9bd + 31560ae commit a09b495

File tree

14 files changed

+187
-67
lines changed

14 files changed

+187
-67
lines changed

alloc/src/collections/btree/map.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ mod entry;
1919
pub use entry::{Entry, OccupiedEntry, OccupiedError, VacantEntry};
2020
use Entry::*;
2121

22-
/// Minimum number of elements in nodes that are not a root.
22+
/// Minimum number of elements in a node that is not a root.
2323
/// We might temporarily have fewer elements during methods.
2424
pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
2525

2626
// A tree in a `BTreeMap` is a tree in the `node` module with additional invariants:
2727
// - Keys must appear in ascending order (according to the key's type).
28-
// - If the root node is internal, it must contain at least 1 element.
28+
// - Every non-leaf node contains at least 1 element (has at least 2 children).
2929
// - Every non-root node contains at least MIN_LEN elements.
3030
//
31-
// An empty map may be represented both by the absence of a root node or by a
31+
// An empty map is represented either by the absence of a root node or by a
3232
// root node that is an empty leaf.
3333

3434
/// A map based on a [B-Tree].
@@ -1735,8 +1735,8 @@ impl<'a, K: 'a, V: 'a> DrainFilterInner<'a, K, V> {
17351735
pub(super) fn size_hint(&self) -> (usize, Option<usize>) {
17361736
// In most of the btree iterators, `self.length` is the number of elements
17371737
// yet to be visited. Here, it includes elements that were visited and that
1738-
// the predicate decided not to drain. Making this upper bound more accurate
1739-
// requires maintaining an extra field and is not worth while.
1738+
// the predicate decided not to drain. Making this upper bound more tight
1739+
// during iteration would require an extra field.
17401740
(0, Some(*self.length))
17411741
}
17421742
}

alloc/src/collections/btree/navigate.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
440440
/// - The given edge must not have been previously returned by counterpart
441441
/// `deallocating_next_back`.
442442
/// - The returned KV handle is only valid to access the key and value,
443-
/// and only valid until the next call to this method or counterpart
444-
/// `deallocating_next_back`.
443+
/// and only valid until the next call to a `deallocating_` method.
445444
unsafe fn deallocating_next(
446445
self,
447446
) -> Option<(Self, Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>)>
@@ -470,8 +469,7 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
470469
/// - The given edge must not have been previously returned by counterpart
471470
/// `deallocating_next`.
472471
/// - The returned KV handle is only valid to access the key and value,
473-
/// and only valid until the next call to this method or counterpart
474-
/// `deallocating_next`.
472+
/// and only valid until the next call to a `deallocating_` method.
475473
unsafe fn deallocating_next_back(
476474
self,
477475
) -> Option<(Self, Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>)>

alloc/src/collections/btree/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::LeafOrInternal> {
574574
/// no cleanup is done on any of the keys, values and other children.
575575
/// This decreases the height by 1 and is the opposite of `push_internal_level`.
576576
///
577-
/// Requires exclusive access to the `Root` object but not to the root node;
577+
/// Requires exclusive access to the `NodeRef` object but not to the root node;
578578
/// it will not invalidate other handles or references to the root node.
579579
///
580580
/// Panics if there is no internal level, i.e., if the root node is a leaf.

alloc/src/vec/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,7 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
21372137
/// in order to be able to clone the passed value.
21382138
/// If you need more flexibility (or want to rely on [`Default`] instead of
21392139
/// [`Clone`]), use [`Vec::resize_with`].
2140+
/// If you only need to resize to a smaller size, use [`Vec::truncate`].
21402141
///
21412142
/// # Examples
21422143
///
@@ -2188,7 +2189,12 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
21882189

21892190
/// Copies elements from `src` range to the end of the vector.
21902191
///
2191-
/// ## Examples
2192+
/// # Panics
2193+
///
2194+
/// Panics if the starting point is greater than the end point or if
2195+
/// the end point is greater than the length of the vector.
2196+
///
2197+
/// # Examples
21922198
///
21932199
/// ```
21942200
/// let mut vec = vec![0, 1, 2, 3, 4];

core/src/array/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,14 @@ impl<T, const N: usize> [T; N] {
368368
}
369369

370370
/// Returns a slice containing the entire array. Equivalent to `&s[..]`.
371-
#[unstable(feature = "array_methods", issue = "76118")]
372-
pub fn as_slice(&self) -> &[T] {
371+
#[stable(feature = "array_as_slice", since = "1.57.0")]
372+
pub const fn as_slice(&self) -> &[T] {
373373
self
374374
}
375375

376376
/// Returns a mutable slice containing the entire array. Equivalent to
377377
/// `&mut s[..]`.
378-
#[unstable(feature = "array_methods", issue = "76118")]
378+
#[stable(feature = "array_as_slice", since = "1.57.0")]
379379
pub fn as_mut_slice(&mut self) -> &mut [T] {
380380
self
381381
}

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#![feature(const_maybe_uninit_assume_init)]
9292
#![feature(const_option)]
9393
#![feature(const_pin)]
94+
#![feature(const_replace)]
9495
#![feature(const_ptr_offset)]
9596
#![feature(const_ptr_offset_from)]
9697
#![feature(const_ptr_read)]

core/src/num/nonzero.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ macro_rules! nonzero_unsigned_operations {
379379
/// ```
380380
#[unstable(feature = "nonzero_ops", issue = "84186")]
381381
#[inline]
382-
pub unsafe fn unchecked_add(self, other: $Int) -> $Ty {
382+
pub const unsafe fn unchecked_add(self, other: $Int) -> $Ty {
383383
// SAFETY: The caller ensures there is no overflow.
384384
unsafe { $Ty::new_unchecked(self.get().unchecked_add(other)) }
385385
}
@@ -750,7 +750,7 @@ macro_rules! nonzero_unsigned_signed_operations {
750750
/// ```
751751
#[unstable(feature = "nonzero_ops", issue = "84186")]
752752
#[inline]
753-
pub unsafe fn unchecked_mul(self, other: $Ty) -> $Ty {
753+
pub const unsafe fn unchecked_mul(self, other: $Ty) -> $Ty {
754754
// SAFETY: The caller ensures there is no overflow.
755755
unsafe { $Ty::new_unchecked(self.get().unchecked_mul(other.get())) }
756756
}

core/src/option.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ impl<T> Option<T> {
544544
/// ```
545545
#[must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead"]
546546
#[inline]
547-
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
548547
#[stable(feature = "rust1", since = "1.0.0")]
548+
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
549549
pub const fn is_some(&self) -> bool {
550550
matches!(*self, Some(_))
551551
}
@@ -564,8 +564,8 @@ impl<T> Option<T> {
564564
#[must_use = "if you intended to assert that this doesn't have a value, consider \
565565
`.and_then(|_| panic!(\"`Option` had a value when expected `None`\"))` instead"]
566566
#[inline]
567-
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
568567
#[stable(feature = "rust1", since = "1.0.0")]
568+
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
569569
pub const fn is_none(&self) -> bool {
570570
!self.is_some()
571571
}
@@ -1318,8 +1318,10 @@ impl<T> Option<T> {
13181318
/// ```
13191319
#[inline]
13201320
#[stable(feature = "rust1", since = "1.0.0")]
1321-
pub fn take(&mut self) -> Option<T> {
1322-
mem::take(self)
1321+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
1322+
pub const fn take(&mut self) -> Option<T> {
1323+
// FIXME replace `mem::replace` by `mem::take` when the latter is const ready
1324+
mem::replace(self, None)
13231325
}
13241326

13251327
/// Replaces the actual value in the option by the value given in parameter,
@@ -1340,8 +1342,9 @@ impl<T> Option<T> {
13401342
/// assert_eq!(old, None);
13411343
/// ```
13421344
#[inline]
1345+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
13431346
#[stable(feature = "option_replace", since = "1.31.0")]
1344-
pub fn replace(&mut self, value: T) -> Option<T> {
1347+
pub const fn replace(&mut self, value: T) -> Option<T> {
13451348
mem::replace(self, Some(value))
13461349
}
13471350

@@ -1446,8 +1449,14 @@ impl<T: Copy> Option<&T> {
14461449
/// assert_eq!(copied, Some(12));
14471450
/// ```
14481451
#[stable(feature = "copied", since = "1.35.0")]
1449-
pub fn copied(self) -> Option<T> {
1450-
self.map(|&t| t)
1452+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
1453+
pub const fn copied(self) -> Option<T> {
1454+
// FIXME: this implementation, which sidesteps using `Option::map` since it's not const
1455+
// ready yet, should be reverted when possible to avoid code repetition
1456+
match self {
1457+
Some(&v) => Some(v),
1458+
None => None,
1459+
}
14511460
}
14521461
}
14531462

core/tests/option.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,19 @@ fn option_const() {
367367

368368
const IS_NONE: bool = OPTION.is_none();
369369
assert!(!IS_NONE);
370+
371+
const COPIED: Option<usize> = OPTION.as_ref().copied();
372+
assert_eq!(COPIED, OPTION);
373+
}
374+
375+
#[test]
376+
const fn option_const_mut() {
377+
// test that the methods of `Option` that take mutable references are usable in a const context
378+
379+
let mut option: Option<usize> = Some(32);
380+
381+
let _take = option.take();
382+
let _replace = option.replace(42);
370383
}
371384

372385
#[test]

std/src/net/ip.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,30 @@ impl IpAddr {
340340
}
341341
}
342342

343+
/// Returns [`true`] if this address is in a range designated for benchmarking.
344+
///
345+
/// See the documentation for [`Ipv4Addr::is_benchmarking()`] and
346+
/// [`Ipv6Addr::is_benchmarking()`] for more details.
347+
///
348+
/// # Examples
349+
///
350+
/// ```
351+
/// #![feature(ip)]
352+
///
353+
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
354+
///
355+
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(198, 19, 255, 255)).is_benchmarking(), true);
356+
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true);
357+
/// ```
358+
#[unstable(feature = "ip", issue = "27709")]
359+
#[inline]
360+
pub const fn is_benchmarking(&self) -> bool {
361+
match self {
362+
IpAddr::V4(ip) => ip.is_benchmarking(),
363+
IpAddr::V6(ip) => ip.is_benchmarking(),
364+
}
365+
}
366+
343367
/// Returns [`true`] if this address is an [`IPv4` address], and [`false`]
344368
/// otherwise.
345369
///
@@ -1449,6 +1473,28 @@ impl Ipv6Addr {
14491473
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
14501474
}
14511475

1476+
/// Returns [`true`] if this is an address reserved for benchmarking (`2001:2::/48`).
1477+
///
1478+
/// This property is defined in [IETF RFC 5180], where it is mistakenly specified as covering the range `2001:0200::/48`.
1479+
/// This is corrected in [IETF RFC Errata 1752] to `2001:0002::/48`.
1480+
///
1481+
/// [IETF RFC 5180]: https://tools.ietf.org/html/rfc5180
1482+
/// [IETF RFC Errata 1752]: https://www.rfc-editor.org/errata_search.php?eid=1752
1483+
///
1484+
/// ```
1485+
/// #![feature(ip)]
1486+
///
1487+
/// use std::net::Ipv6Addr;
1488+
///
1489+
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc613, 0x0).is_benchmarking(), false);
1490+
/// assert_eq!(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0).is_benchmarking(), true);
1491+
/// ```
1492+
#[unstable(feature = "ip", issue = "27709")]
1493+
#[inline]
1494+
pub const fn is_benchmarking(&self) -> bool {
1495+
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0x2) && (self.segments()[2] == 0)
1496+
}
1497+
14521498
/// Returns [`true`] if the address is a globally routable unicast address.
14531499
///
14541500
/// The following return false:
@@ -1589,7 +1635,7 @@ impl Ipv6Addr {
15891635
/// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`
15901636
/// All addresses *not* starting with either all zeroes or `::ffff` will return `None`.
15911637
///
1592-
/// [IPv4 address]: Ipv4Addr
1638+
/// [`IPv4` address]: Ipv4Addr
15931639
/// [IPv4-compatible]: Ipv6Addr#ipv4-compatible-ipv6-addresses
15941640
/// [IPv4-mapped]: Ipv6Addr#ipv4-mapped-ipv6-addresses
15951641
/// [IETF RFC 4291 section 2.5.5.1]: https://tools.ietf.org/html/rfc4291#section-2.5.5.1

0 commit comments

Comments
 (0)