diff options
| author | bors <bors@rust-lang.org> | 2021-04-23 21:03:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-23 21:03:57 +0000 |
| commit | bb491ed23937aef876622e4beb68ae95938b3bf9 (patch) | |
| tree | d5383a2182442ee9c2dd0b0dae79dc04a2c98bc4 /library | |
| parent | 481ba16439299eb07058a7107352c558fdba7f96 (diff) | |
| parent | 62db03cd623c0c3a6cf13a1b8c3c13581a416fcc (diff) | |
| download | rust-bb491ed23937aef876622e4beb68ae95938b3bf9.tar.gz rust-bb491ed23937aef876622e4beb68ae95938b3bf9.zip | |
Auto merge of #84490 - JohnTitor:rollup-wrdj4ko, r=JohnTitor
Rollup of 11 pull requests Successful merges: - #80805 (Improve `Iterator::by_ref` example) - #84248 (Remove duplicated fn(Box<[T]>) -> Vec<T>) - #84321 (rustdoc: Convert sub-variant toggle to HTML) - #84359 (:arrow_up: rust-analyzer) - #84374 (Clean up .gitignore) - #84387 (Move `sys_common::poison` to `sync::poison`) - #84430 (doc/platform-support: clarify UEFI support) - #84433 (Prevent control, shift and alt keys to make search input lose focus) - #84444 (doc: Get rid of "[+] show undocumented items" toggle on numeric From impls) - #84456 (Fix ICE if original_span(fn_sig) returns a span not in body sourcefile) - #84469 (Update comment on `PrimTy::name_str`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 3 | ||||
| -rw-r--r-- | library/core/src/convert/num.rs | 16 | ||||
| -rw-r--r-- | library/core/src/iter/traits/iterator.rs | 31 | ||||
| -rw-r--r-- | library/std/src/sync/condvar.rs | 3 | ||||
| -rw-r--r-- | library/std/src/sync/mod.rs | 5 | ||||
| -rw-r--r-- | library/std/src/sync/mutex.rs | 2 | ||||
| -rw-r--r-- | library/std/src/sync/poison.rs (renamed from library/std/src/sys_common/poison.rs) | 16 | ||||
| -rw-r--r-- | library/std/src/sync/rwlock.rs | 2 | ||||
| -rw-r--r-- | library/std/src/sys_common/mod.rs | 1 |
9 files changed, 36 insertions, 43 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 1b78356fde5..e459442dfcf 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2810,8 +2810,7 @@ impl<T, A: Allocator> From<Box<[T], A>> for Vec<T, A> { /// assert_eq!(Vec::from(b), vec![1, 2, 3]); /// ``` fn from(s: Box<[T], A>) -> Self { - let len = s.len(); - Self { buf: RawVec::from_box(s), len } + s.into_vec() } } diff --git a/library/core/src/convert/num.rs b/library/core/src/convert/num.rs index 5b113610a5d..a522b7da3bd 100644 --- a/library/core/src/convert/num.rs +++ b/library/core/src/convert/num.rs @@ -45,8 +45,10 @@ impl_float_to_int!(f64 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize); macro_rules! impl_from { ($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => { #[$attr] - #[doc = $doc] impl From<$Small> for $Large { + // Rustdocs on the impl block show a "[+] show undocumented items" toggle. + // Rustdocs on functions do not. + #[doc = $doc] #[inline] fn from(small: $Small) -> Self { small as Self @@ -383,8 +385,10 @@ use crate::num::NonZeroUsize; macro_rules! nzint_impl_from { ($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => { #[$attr] - #[doc = $doc] impl From<$Small> for $Large { + // Rustdocs on the impl block show a "[+] show undocumented items" toggle. + // Rustdocs on functions do not. + #[doc = $doc] #[inline] fn from(small: $Small) -> Self { // SAFETY: input type guarantees the value is non-zero @@ -450,10 +454,12 @@ nzint_impl_from! { NonZeroU64, NonZeroI128, #[stable(feature = "nz_int_conv", si macro_rules! nzint_impl_try_from_int { ($Int: ty, $NonZeroInt: ty, #[$attr:meta], $doc: expr) => { #[$attr] - #[doc = $doc] impl TryFrom<$Int> for $NonZeroInt { type Error = TryFromIntError; + // Rustdocs on the impl block show a "[+] show undocumented items" toggle. + // Rustdocs on functions do not. + #[doc = $doc] #[inline] fn try_from(value: $Int) -> Result<Self, Self::Error> { Self::new(value).ok_or(TryFromIntError(())) @@ -489,10 +495,12 @@ nzint_impl_try_from_int! { isize, NonZeroIsize, #[stable(feature = "nzint_try_fr macro_rules! nzint_impl_try_from_nzint { ($From:ty => $To:ty, $doc: expr) => { #[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")] - #[doc = $doc] impl TryFrom<$From> for $To { type Error = TryFromIntError; + // Rustdocs on the impl block show a "[+] show undocumented items" toggle. + // Rustdocs on functions do not. + #[doc = $doc] #[inline] fn try_from(value: $From) -> Result<Self, Self::Error> { TryFrom::try_from(value.get()).map(|v| { diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index abd44b47f98..9b0f9544f8e 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -1646,31 +1646,16 @@ pub trait Iterator { /// Basic usage: /// /// ``` - /// let a = [1, 2, 3]; - /// - /// let iter = a.iter(); - /// - /// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i); - /// - /// assert_eq!(sum, 6); - /// - /// // if we try to use iter again, it won't work. The following line - /// // gives "error: use of moved value: `iter` - /// // assert_eq!(iter.next(), None); + /// let mut words = vec!["hello", "world", "of", "Rust"].into_iter(); /// - /// // let's try that again - /// let a = [1, 2, 3]; - /// - /// let mut iter = a.iter(); - /// - /// // instead, we add in a .by_ref() - /// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i); + /// // Take the first two words. + /// let hello_world: Vec<_> = words.by_ref().take(2).collect(); + /// assert_eq!(hello_world, vec!["hello", "world"]); /// - /// assert_eq!(sum, 3); - /// - /// // now this is just fine: - /// assert_eq!(iter.next(), Some(&3)); - /// assert_eq!(iter.next(), None); + /// // Collect the rest of the words. + /// // We can only do this because we used `by_ref` earlier. + /// let of_rust: Vec<_> = words.collect(); + /// assert_eq!(of_rust, vec!["of", "Rust"]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn by_ref(&mut self) -> &mut Self diff --git a/library/std/src/sync/condvar.rs b/library/std/src/sync/condvar.rs index 60be63c9543..2f0b32c90d0 100644 --- a/library/std/src/sync/condvar.rs +++ b/library/std/src/sync/condvar.rs @@ -2,9 +2,8 @@ mod tests; use crate::fmt; -use crate::sync::{mutex, MutexGuard, PoisonError}; +use crate::sync::{mutex, poison, LockResult, MutexGuard, PoisonError}; use crate::sys_common::condvar as sys; -use crate::sys_common::poison::{self, LockResult}; use crate::time::{Duration, Instant}; /// A type indicating whether a timed wait on a condition variable returned diff --git a/library/std/src/sync/mod.rs b/library/std/src/sync/mod.rs index b6699910b07..ee35598bab5 100644 --- a/library/std/src/sync/mod.rs +++ b/library/std/src/sync/mod.rs @@ -166,9 +166,9 @@ pub use self::mutex::{Mutex, MutexGuard}; #[allow(deprecated)] pub use self::once::{Once, OnceState, ONCE_INIT}; #[stable(feature = "rust1", since = "1.0.0")] -pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +pub use self::poison::{LockResult, PoisonError, TryLockError, TryLockResult}; #[stable(feature = "rust1", since = "1.0.0")] -pub use crate::sys_common::poison::{LockResult, PoisonError, TryLockError, TryLockResult}; +pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; pub mod mpsc; @@ -176,4 +176,5 @@ mod barrier; mod condvar; mod mutex; mod once; +mod poison; mod rwlock; diff --git a/library/std/src/sync/mutex.rs b/library/std/src/sync/mutex.rs index 98c34282e0c..2615bea6592 100644 --- a/library/std/src/sync/mutex.rs +++ b/library/std/src/sync/mutex.rs @@ -6,8 +6,8 @@ use crate::fmt; use crate::mem; use crate::ops::{Deref, DerefMut}; use crate::ptr; +use crate::sync::{poison, LockResult, TryLockError, TryLockResult}; use crate::sys_common::mutex as sys; -use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult}; /// A mutual exclusion primitive useful for protecting shared data /// diff --git a/library/std/src/sys_common/poison.rs b/library/std/src/sync/poison.rs index 1f71187f1b4..05e1833c3e5 100644 --- a/library/std/src/sys_common/poison.rs +++ b/library/std/src/sync/poison.rs @@ -3,9 +3,6 @@ use crate::fmt; use crate::sync::atomic::{AtomicBool, Ordering}; use crate::thread; -#[allow(unused_imports)] // for intra-doc links -use crate::sync::{Mutex, RwLock}; - pub struct Flag { failed: AtomicBool, } @@ -80,6 +77,8 @@ pub struct Guard { /// } /// }; /// ``` +/// [`Mutex`]: crate::sync::Mutex +/// [`RwLock`]: crate::sync::RwLock #[stable(feature = "rust1", since = "1.0.0")] pub struct PoisonError<T> { guard: T, @@ -89,9 +88,11 @@ pub struct PoisonError<T> { /// can occur while trying to acquire a lock, from the [`try_lock`] method on a /// [`Mutex`] or the [`try_read`] and [`try_write`] methods on an [`RwLock`]. /// -/// [`try_lock`]: Mutex::try_lock -/// [`try_read`]: RwLock::try_read -/// [`try_write`]: RwLock::try_write +/// [`try_lock`]: crate::sync::Mutex::try_lock +/// [`try_read`]: crate::sync::RwLock::try_read +/// [`try_write`]: crate::sync::RwLock::try_write +/// [`Mutex`]: crate::sync::Mutex +/// [`RwLock`]: crate::sync::RwLock #[stable(feature = "rust1", since = "1.0.0")] pub enum TryLockError<T> { /// The lock could not be acquired because another thread failed while holding @@ -149,7 +150,8 @@ impl<T> Error for PoisonError<T> { impl<T> PoisonError<T> { /// Creates a `PoisonError`. /// - /// This is generally created by methods like [`Mutex::lock`] or [`RwLock::read`]. + /// This is generally created by methods like [`Mutex::lock`](crate::sync::Mutex::lock) + /// or [`RwLock::read`](crate::sync::RwLock::read). #[stable(feature = "sync_poison", since = "1.2.0")] pub fn new(guard: T) -> PoisonError<T> { PoisonError { guard } diff --git a/library/std/src/sync/rwlock.rs b/library/std/src/sync/rwlock.rs index 351804ec979..b01bcec1361 100644 --- a/library/std/src/sync/rwlock.rs +++ b/library/std/src/sync/rwlock.rs @@ -6,7 +6,7 @@ use crate::fmt; use crate::mem; use crate::ops::{Deref, DerefMut}; use crate::ptr; -use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult}; +use crate::sync::{poison, LockResult, TryLockError, TryLockResult}; use crate::sys_common::rwlock as sys; /// A reader-writer lock diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index 23a3a0e907d..4979bc0b5af 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -59,7 +59,6 @@ pub mod mutex; // when generating documentation. #[cfg(any(doc, not(windows)))] pub mod os_str_bytes; -pub mod poison; pub mod process; pub mod remutex; pub mod rwlock; |
