Skip to content

Commit 24bba83

Browse files
committed
Auto merge of rust-lang#87689 - JohnTitor:rollup-ns38b56, r=JohnTitor
Rollup of 13 pull requests Successful merges: - rust-lang#86183 (Change environment variable getters to error recoverably) - rust-lang#86439 (Remove `Ipv4Addr::is_ietf_protocol_assignment`) - rust-lang#86509 (Move `os_str_bytes` to `sys::unix`) - rust-lang#86593 (Partially stabilize `const_slice_first_last`) - rust-lang#86936 (Add documentation for `Ipv6MulticastScope`) - rust-lang#87282 (Ensure `./x.py dist` adheres to `build.tools`) - rust-lang#87468 (Update rustfmt) - rust-lang#87504 (Update mdbook.) - rust-lang#87608 (Remove unused field `Session.system_library_path`) - rust-lang#87629 (Consistent spelling of "adapter" in the standard library) - rust-lang#87633 (Update compiler_builtins to fix i128 shift/mul on thumbv6m) - rust-lang#87644 (Recommend `swap_remove` in `Vec::remove` docs) - rust-lang#87653 (mark a UB doctest as no_run) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6b04a80 + b219c92 commit 24bba83

File tree

26 files changed

+124
-141
lines changed

26 files changed

+124
-141
lines changed

alloc/src/vec/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,12 @@ impl<T, A: Allocator> Vec<T, A> {
13601360
/// Removes and returns the element at position `index` within the vector,
13611361
/// shifting all elements after it to the left.
13621362
///
1363+
/// Note: Because this shifts over the remaining elements, it has a
1364+
/// worst-case performance of O(n). If you don't need the order of elements
1365+
/// to be preserved, use [`swap_remove`] instead.
1366+
///
1367+
/// [`swap_remove`]: Vec::swap_remove
1368+
///
13631369
/// # Panics
13641370
///
13651371
/// Panics if `index` is out of bounds.

core/src/alloc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ pub unsafe trait Allocator {
338338
Ok(new_ptr)
339339
}
340340

341-
/// Creates a "by reference" adaptor for this instance of `Allocator`.
341+
/// Creates a "by reference" adapter for this instance of `Allocator`.
342342
///
343-
/// The returned adaptor also implements `Allocator` and will simply borrow this.
343+
/// The returned adapter also implements `Allocator` and will simply borrow this.
344344
#[inline(always)]
345345
fn by_ref(&self) -> &Self
346346
where

core/src/iter/traits/iterator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ pub trait Iterator {
694694
/// more idiomatic to use a `for` loop, but `for_each` may be more legible
695695
/// when processing items at the end of longer iterator chains. In some
696696
/// cases `for_each` may also be faster than a loop, because it will use
697-
/// internal iteration on adaptors like `Chain`.
697+
/// internal iteration on adapters like `Chain`.
698698
///
699699
/// [`for`]: ../../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
700700
///
@@ -1293,7 +1293,7 @@ pub trait Iterator {
12931293
Take::new(self, n)
12941294
}
12951295

1296-
/// An iterator adaptor similar to [`fold`] that holds internal state and
1296+
/// An iterator adapter similar to [`fold`] that holds internal state and
12971297
/// produces a new iterator.
12981298
///
12991299
/// [`fold`]: Iterator::fold
@@ -1604,7 +1604,7 @@ pub trait Iterator {
16041604

16051605
/// Borrows an iterator, rather than consuming it.
16061606
///
1607-
/// This is useful to allow applying iterator adaptors while still
1607+
/// This is useful to allow applying iterator adapters while still
16081608
/// retaining ownership of the original iterator.
16091609
///
16101610
/// # Examples

core/src/ptr/non_null.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,14 @@ impl<T: ?Sized> NonNull<T> {
173173
///
174174
/// let mut x = 0u32;
175175
/// let ptr = unsafe { NonNull::new_unchecked(&mut x as *mut _) };
176+
/// ```
177+
///
178+
/// *Incorrect* usage of this function:
179+
///
180+
/// ```rust,no_run
181+
/// use std::ptr::NonNull;
176182
///
177-
/// // NEVER DO THAT!!!
183+
/// // NEVER DO THAT!!! This is undefined behavior. ⚠️
178184
/// let ptr = unsafe { NonNull::<u32>::new_unchecked(std::ptr::null_mut()) };
179185
/// ```
180186
#[stable(feature = "nonnull", since = "1.25.0")]

core/src/slice/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<T> [T] {
139139
/// assert_eq!(None, w.first());
140140
/// ```
141141
#[stable(feature = "rust1", since = "1.0.0")]
142-
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
142+
#[rustc_const_stable(feature = "const_slice_first_last_not_mut", since = "1.56.0")]
143143
#[inline]
144144
pub const fn first(&self) -> Option<&T> {
145145
if let [first, ..] = self { Some(first) } else { None }
@@ -177,7 +177,7 @@ impl<T> [T] {
177177
/// }
178178
/// ```
179179
#[stable(feature = "slice_splits", since = "1.5.0")]
180-
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
180+
#[rustc_const_stable(feature = "const_slice_first_last_not_mut", since = "1.56.0")]
181181
#[inline]
182182
pub const fn split_first(&self) -> Option<(&T, &[T])> {
183183
if let [first, tail @ ..] = self { Some((first, tail)) } else { None }
@@ -217,7 +217,7 @@ impl<T> [T] {
217217
/// }
218218
/// ```
219219
#[stable(feature = "slice_splits", since = "1.5.0")]
220-
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
220+
#[rustc_const_stable(feature = "const_slice_first_last_not_mut", since = "1.56.0")]
221221
#[inline]
222222
pub const fn split_last(&self) -> Option<(&T, &[T])> {
223223
if let [init @ .., last] = self { Some((last, init)) } else { None }
@@ -256,7 +256,7 @@ impl<T> [T] {
256256
/// assert_eq!(None, w.last());
257257
/// ```
258258
#[stable(feature = "rust1", since = "1.0.0")]
259-
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
259+
#[rustc_const_stable(feature = "const_slice_first_last_not_mut", since = "1.56.0")]
260260
#[inline]
261261
pub const fn last(&self) -> Option<&T> {
262262
if let [.., last] = self { Some(last) } else { None }

core/tests/iter/adapters/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use core::cell::Cell;
2424

2525
/// An iterator that panics whenever `next` or next_back` is called
2626
/// after `None` has already been returned. This does not violate
27-
/// `Iterator`'s contract. Used to test that iterator adaptors don't
27+
/// `Iterator`'s contract. Used to test that iterator adapters don't
2828
/// poll their inner iterators after exhausting them.
2929
pub struct NonFused<I> {
3030
iter: I,

std/src/env.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,9 @@ impl fmt::Debug for VarsOs {
185185
///
186186
/// # Errors
187187
///
188-
/// Errors if the environment variable is not present.
189-
/// Errors if the environment variable is not valid Unicode. If this is not desired, consider using
190-
/// [`var_os`].
191-
///
192-
/// # Panics
193-
///
194-
/// This function may panic if `key` is empty, contains an ASCII equals sign
195-
/// `'='` or the NUL character `'\0'`, or when the value contains the NUL
196-
/// character.
188+
/// Returns `[None]` if the environment variable isn't set.
189+
/// Returns `[None]` if the environment variable is not valid Unicode. If this is not
190+
/// desired, consider using [`var_os`].
197191
///
198192
/// # Examples
199193
///
@@ -219,18 +213,17 @@ fn _var(key: &OsStr) -> Result<String, VarError> {
219213
}
220214

221215
/// Fetches the environment variable `key` from the current process, returning
222-
/// [`None`] if the variable isn't set.
223-
///
224-
/// # Panics
225-
///
226-
/// This function may panic if `key` is empty, contains an ASCII equals sign
227-
/// `'='` or the NUL character `'\0'`, or when the value contains the NUL
228-
/// character.
216+
/// [`None`] if the variable isn't set or there's another error.
229217
///
230218
/// Note that the method will not check if the environment variable
231219
/// is valid Unicode. If you want to have an error on invalid UTF-8,
232220
/// use the [`var`] function instead.
233221
///
222+
/// # Errors
223+
///
224+
/// Returns `[None]` if the variable isn't set.
225+
/// May return `[None]` if the variable value contains the NUL character.
226+
///
234227
/// # Examples
235228
///
236229
/// ```
@@ -249,7 +242,6 @@ pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
249242

250243
fn _var_os(key: &OsStr) -> Option<OsString> {
251244
os_imp::getenv(key)
252-
.unwrap_or_else(|e| panic!("failed to get environment variable `{:?}`: {}", key, e))
253245
}
254246

255247
/// The error type for operations interacting with environment variables.

std/src/io/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,9 @@ pub trait Read {
810810
default_read_exact(self, buf)
811811
}
812812

813-
/// Creates a "by reference" adaptor for this instance of `Read`.
813+
/// Creates a "by reference" adapter for this instance of `Read`.
814814
///
815-
/// The returned adaptor also implements `Read` and will simply borrow this
815+
/// The returned adapter also implements `Read` and will simply borrow this
816816
/// current reader.
817817
///
818818
/// # Examples
@@ -889,7 +889,7 @@ pub trait Read {
889889
Bytes { inner: self }
890890
}
891891

892-
/// Creates an adaptor which will chain this stream with another.
892+
/// Creates an adapter which will chain this stream with another.
893893
///
894894
/// The returned `Read` instance will first read all bytes from this object
895895
/// until EOF is encountered. Afterwards the output is equivalent to the
@@ -927,7 +927,7 @@ pub trait Read {
927927
Chain { first: self, second: next, done_first: false }
928928
}
929929

930-
/// Creates an adaptor which will read at most `limit` bytes from it.
930+
/// Creates an adapter which will read at most `limit` bytes from it.
931931
///
932932
/// This function returns a new instance of `Read` which will read at most
933933
/// `limit` bytes, after which it will always return EOF ([`Ok(0)`]). Any
@@ -1326,7 +1326,7 @@ impl Initializer {
13261326
/// * The [`write`] method will attempt to write some data into the object,
13271327
/// returning how many bytes were successfully written.
13281328
///
1329-
/// * The [`flush`] method is useful for adaptors and explicit buffers
1329+
/// * The [`flush`] method is useful for adapters and explicit buffers
13301330
/// themselves for ensuring that all buffered data has been pushed out to the
13311331
/// 'true sink'.
13321332
///
@@ -1646,12 +1646,12 @@ pub trait Write {
16461646
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> Result<()> {
16471647
// Create a shim which translates a Write to a fmt::Write and saves
16481648
// off I/O errors. instead of discarding them
1649-
struct Adaptor<'a, T: ?Sized + 'a> {
1649+
struct Adapter<'a, T: ?Sized + 'a> {
16501650
inner: &'a mut T,
16511651
error: Result<()>,
16521652
}
16531653

1654-
impl<T: Write + ?Sized> fmt::Write for Adaptor<'_, T> {
1654+
impl<T: Write + ?Sized> fmt::Write for Adapter<'_, T> {
16551655
fn write_str(&mut self, s: &str) -> fmt::Result {
16561656
match self.inner.write_all(s.as_bytes()) {
16571657
Ok(()) => Ok(()),
@@ -1663,7 +1663,7 @@ pub trait Write {
16631663
}
16641664
}
16651665

1666-
let mut output = Adaptor { inner: self, error: Ok(()) };
1666+
let mut output = Adapter { inner: self, error: Ok(()) };
16671667
match fmt::write(&mut output, fmt) {
16681668
Ok(()) => Ok(()),
16691669
Err(..) => {
@@ -1677,9 +1677,9 @@ pub trait Write {
16771677
}
16781678
}
16791679

1680-
/// Creates a "by reference" adaptor for this instance of `Write`.
1680+
/// Creates a "by reference" adapter for this instance of `Write`.
16811681
///
1682-
/// The returned adaptor also implements `Write` and will simply borrow this
1682+
/// The returned adapter also implements `Write` and will simply borrow this
16831683
/// current writer.
16841684
///
16851685
/// # Examples
@@ -2263,7 +2263,7 @@ pub trait BufRead: Read {
22632263
}
22642264
}
22652265

2266-
/// Adaptor to chain together two readers.
2266+
/// Adapter to chain together two readers.
22672267
///
22682268
/// This struct is generally created by calling [`chain`] on a reader.
22692269
/// Please see the documentation of [`chain`] for more details.
@@ -2414,7 +2414,7 @@ impl<T, U> SizeHint for Chain<T, U> {
24142414
}
24152415
}
24162416

2417-
/// Reader adaptor which limits the bytes read from an underlying reader.
2417+
/// Reader adapter which limits the bytes read from an underlying reader.
24182418
///
24192419
/// This struct is generally created by calling [`take`] on a reader.
24202420
/// Please see the documentation of [`take`] for more details.

std/src/net/ip.rs

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,58 @@ pub struct Ipv6Addr {
116116
inner: c::in6_addr,
117117
}
118118

119-
#[allow(missing_docs)]
119+
/// Scope of an [IPv6 multicast address] as defined in [IETF RFC 7346 section 2].
120+
///
121+
/// # Stability Guarantees
122+
///
123+
/// Not all possible values for a multicast scope have been assigned.
124+
/// Future RFCs may introduce new scopes, which will be added as variants to this enum;
125+
/// because of this the enum is marked as `#[non_exhaustive]`.
126+
///
127+
/// # Examples
128+
/// ```
129+
/// #![feature(ip)]
130+
///
131+
/// use std::net::Ipv6Addr;
132+
/// use std::net::Ipv6MulticastScope::*;
133+
///
134+
/// // An IPv6 multicast address with global scope (`ff0e::`).
135+
/// let address = Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0);
136+
///
137+
/// // Will print "Global scope".
138+
/// match address.multicast_scope() {
139+
/// Some(InterfaceLocal) => println!("Interface-Local scope"),
140+
/// Some(LinkLocal) => println!("Link-Local scope"),
141+
/// Some(RealmLocal) => println!("Realm-Local scope"),
142+
/// Some(AdminLocal) => println!("Admin-Local scope"),
143+
/// Some(SiteLocal) => println!("Site-Local scope"),
144+
/// Some(OrganizationLocal) => println!("Organization-Local scope"),
145+
/// Some(Global) => println!("Global scope"),
146+
/// Some(_) => println!("Unknown scope"),
147+
/// None => println!("Not a multicast address!")
148+
/// }
149+
///
150+
/// ```
151+
///
152+
/// [IPv6 multicast address]: Ipv6Addr
153+
/// [IETF RFC 7346 section 2]: https://tools.ietf.org/html/rfc7346#section-2
120154
#[derive(Copy, PartialEq, Eq, Clone, Hash, Debug)]
121155
#[unstable(feature = "ip", issue = "27709")]
156+
#[non_exhaustive]
122157
pub enum Ipv6MulticastScope {
158+
/// Interface-Local scope.
123159
InterfaceLocal,
160+
/// Link-Local scope.
124161
LinkLocal,
162+
/// Realm-Local scope.
125163
RealmLocal,
164+
/// Admin-Local scope.
126165
AdminLocal,
166+
/// Site-Local scope.
127167
SiteLocal,
168+
/// Organization-Local scope.
128169
OrganizationLocal,
170+
/// Global scope.
129171
Global,
130172
}
131173

@@ -486,8 +528,7 @@ impl Ipv4Addr {
486528
/// - addresses used for documentation (see [`Ipv4Addr::is_documentation()`])
487529
/// - the unspecified address (see [`Ipv4Addr::is_unspecified()`]), and the whole
488530
/// `0.0.0.0/8` block
489-
/// - addresses reserved for future protocols (see
490-
/// [`Ipv4Addr::is_ietf_protocol_assignment()`], except
531+
/// - addresses reserved for future protocols, except
491532
/// `192.0.0.9/32` and `192.0.0.10/32` which are globally routable
492533
/// - addresses reserved for future use (see [`Ipv4Addr::is_reserved()`]
493534
/// - addresses reserved for networking devices benchmarking (see
@@ -560,7 +601,8 @@ impl Ipv4Addr {
560601
&& !self.is_broadcast()
561602
&& !self.is_documentation()
562603
&& !self.is_shared()
563-
&& !self.is_ietf_protocol_assignment()
604+
// addresses reserved for future protocols (`192.0.0.0/24`)
605+
&& !(self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0)
564606
&& !self.is_reserved()
565607
&& !self.is_benchmarking()
566608
// Make sure the address is not in 0.0.0.0/8
@@ -589,40 +631,6 @@ impl Ipv4Addr {
589631
self.octets()[0] == 100 && (self.octets()[1] & 0b1100_0000 == 0b0100_0000)
590632
}
591633

592-
/// Returns [`true`] if this address is part of `192.0.0.0/24`, which is reserved to
593-
/// IANA for IETF protocol assignments, as documented in [IETF RFC 6890].
594-
///
595-
/// Note that parts of this block are in use:
596-
///
597-
/// - `192.0.0.8/32` is the "IPv4 dummy address" (see [IETF RFC 7600])
598-
/// - `192.0.0.9/32` is the "Port Control Protocol Anycast" (see [IETF RFC 7723])
599-
/// - `192.0.0.10/32` is used for NAT traversal (see [IETF RFC 8155])
600-
///
601-
/// [IETF RFC 6890]: https://tools.ietf.org/html/rfc6890
602-
/// [IETF RFC 7600]: https://tools.ietf.org/html/rfc7600
603-
/// [IETF RFC 7723]: https://tools.ietf.org/html/rfc7723
604-
/// [IETF RFC 8155]: https://tools.ietf.org/html/rfc8155
605-
///
606-
/// # Examples
607-
///
608-
/// ```
609-
/// #![feature(ip)]
610-
/// use std::net::Ipv4Addr;
611-
///
612-
/// assert_eq!(Ipv4Addr::new(192, 0, 0, 0).is_ietf_protocol_assignment(), true);
613-
/// assert_eq!(Ipv4Addr::new(192, 0, 0, 8).is_ietf_protocol_assignment(), true);
614-
/// assert_eq!(Ipv4Addr::new(192, 0, 0, 9).is_ietf_protocol_assignment(), true);
615-
/// assert_eq!(Ipv4Addr::new(192, 0, 0, 255).is_ietf_protocol_assignment(), true);
616-
/// assert_eq!(Ipv4Addr::new(192, 0, 1, 0).is_ietf_protocol_assignment(), false);
617-
/// assert_eq!(Ipv4Addr::new(191, 255, 255, 255).is_ietf_protocol_assignment(), false);
618-
/// ```
619-
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
620-
#[unstable(feature = "ip", issue = "27709")]
621-
#[inline]
622-
pub const fn is_ietf_protocol_assignment(&self) -> bool {
623-
self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0
624-
}
625-
626634
/// Returns [`true`] if this address part of the `198.18.0.0/15` range, which is reserved for
627635
/// network devices benchmarking. This range is defined in [IETF RFC 2544] as `192.18.0.0`
628636
/// through `198.19.255.255` but [errata 423] corrects it to `198.18.0.0/15`.

0 commit comments

Comments
 (0)