Skip to content

Commit 71d02d4

Browse files
committed
Auto merge of rust-lang#121078 - oli-obk:rollup-p11zsav, r=oli-obk
Rollup of 13 pull requests Successful merges: - rust-lang#116387 (Additional doc links and explanation of `Wake`.) - rust-lang#118738 (Netbsd10 update) - rust-lang#118890 (Clarify the lifetimes of allocations returned by the `Allocator` trait) - rust-lang#120498 (Uplift `TypeVisitableExt` into `rustc_type_ir`) - rust-lang#120530 (Be less confident when `dyn` suggestion is not checked for object safety) - rust-lang#120915 (Fix suggestion span for `?Sized` when param type has default) - rust-lang#121015 (Optimize `delayed_bug` handling.) - rust-lang#121024 (implement `Default` for `AsciiChar`) - rust-lang#121039 (Correctly compute adjustment casts in GVN) - rust-lang#121045 (Fix two UI tests with incorrect directive / invalid revision) - rust-lang#121049 (Do not point at `#[allow(_)]` as the reason for compat lint triggering) - rust-lang#121071 (Use fewer delayed bugs.) - rust-lang#121073 (Fix typos in `OneLock` doc) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6a68707 + f3650d6 commit 71d02d4

File tree

8 files changed

+49
-15
lines changed

8 files changed

+49
-15
lines changed

alloc/src/task.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use core::task::Waker;
1919
/// The implementation of waking a task on an executor.
2020
///
2121
/// This trait can be used to create a [`Waker`]. An executor can define an
22-
/// implementation of this trait, and use that to construct a Waker to pass
22+
/// implementation of this trait, and use that to construct a [`Waker`] to pass
2323
/// to the tasks that are executed on that executor.
2424
///
2525
/// This trait is a memory-safe and ergonomic alternative to constructing a
@@ -28,7 +28,14 @@ use core::task::Waker;
2828
/// those for embedded systems) cannot use this API, which is why [`RawWaker`]
2929
/// exists as an alternative for those systems.
3030
///
31-
/// [arc]: ../../std/sync/struct.Arc.html
31+
/// To construct a [`Waker`] from some type `W` implementing this trait,
32+
/// wrap it in an [`Arc<W>`](Arc) and call `Waker::from()` on that.
33+
/// It is also possible to convert to [`RawWaker`] in the same way.
34+
///
35+
/// <!-- Ideally we'd link to the `From` impl, but rustdoc doesn't generate any page for it within
36+
/// `alloc` because `alloc` neither defines nor re-exports `From` or `Waker`, and we can't
37+
/// link ../../std/task/struct.Waker.html#impl-From%3CArc%3CW,+Global%3E%3E-for-Waker
38+
/// without getting a link-checking error in CI. -->
3239
///
3340
/// # Examples
3441
///
@@ -100,7 +107,7 @@ pub trait Wake {
100107
#[cfg(target_has_atomic = "ptr")]
101108
#[stable(feature = "wake_trait", since = "1.51.0")]
102109
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
103-
/// Use a `Wake`-able type as a `Waker`.
110+
/// Use a [`Wake`]-able type as a `Waker`.
104111
///
105112
/// No heap allocations or atomic operations are used for this conversion.
106113
fn from(waker: Arc<W>) -> Waker {

core/src/alloc/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ impl fmt::Display for AllocError {
9595
/// # Safety
9696
///
9797
/// * Memory blocks returned from an allocator that are [*currently allocated*] must point to
98-
/// valid memory and retain their validity while they are [*currently allocated*] and at
99-
/// least one of the instance and all of its clones has not been dropped.
98+
/// valid memory and retain their validity while they are [*currently allocated*] and the shorter
99+
/// of:
100+
/// - the borrow-checker lifetime of the allocator type itself.
101+
/// - as long as at least one of the instance and all of its clones has not been dropped.
100102
///
101103
/// * copying, cloning, or moving the allocator must not invalidate memory blocks returned from this
102104
/// allocator. A copied or cloned allocator must behave like the same allocator, and
@@ -114,6 +116,10 @@ pub unsafe trait Allocator {
114116
/// The returned block may have a larger size than specified by `layout.size()`, and may or may
115117
/// not have its contents initialized.
116118
///
119+
/// The returned block of memory remains valid as long as it is [*currently allocated*] and the shorter of:
120+
/// - the borrow-checker lifetime of the allocator type itself.
121+
/// - as long as at the allocator and all its clones has not been dropped.
122+
///
117123
/// # Errors
118124
///
119125
/// Returning `Err` indicates that either memory is exhausted or `layout` does not meet

core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use crate::mem::transmute;
5858
#[unstable(feature = "ascii_char", issue = "110998")]
5959
#[repr(u8)]
6060
pub enum AsciiChar {
61-
/// U+0000
61+
/// U+0000 (The default variant)
6262
#[unstable(feature = "ascii_char_variants", issue = "110998")]
6363
Null = 0,
6464
/// U+0001

core/src/default.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
#![stable(feature = "rust1", since = "1.0.0")]
44

5+
use crate::ascii::Char as AsciiChar;
6+
57
/// A trait for giving a type a useful default value.
68
///
79
/// Sometimes, you want to fall back to some kind of default value, and
@@ -158,6 +160,7 @@ macro_rules! default_impl {
158160
default_impl! { (), (), "Returns the default value of `()`" }
159161
default_impl! { bool, false, "Returns the default value of `false`" }
160162
default_impl! { char, '\x00', "Returns the default value of `\\x00`" }
163+
default_impl! { AsciiChar, AsciiChar::Null, "Returns the default value of `Null`" }
161164

162165
default_impl! { usize, 0, "Returns the default value of `0`" }
163166
default_impl! { u8, 0, "Returns the default value of `0`" }

core/src/task/wake.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ use crate::ptr;
99
/// A `RawWaker` allows the implementor of a task executor to create a [`Waker`]
1010
/// or a [`LocalWaker`] which provides customized wakeup behavior.
1111
///
12-
/// [vtable]: https://en.wikipedia.org/wiki/Virtual_method_table
13-
///
1412
/// It consists of a data pointer and a [virtual function pointer table (vtable)][vtable]
1513
/// that customizes the behavior of the `RawWaker`.
14+
///
15+
/// `RawWaker`s are unsafe to use.
16+
/// Implementing the [`Wake`] trait is a safe alternative that requires memory allocation.
17+
///
18+
/// [vtable]: https://en.wikipedia.org/wiki/Virtual_method_table
19+
/// [`Wake`]: ../../alloc/task/trait.Wake.html
1620
#[derive(PartialEq, Debug)]
1721
#[stable(feature = "futures_api", since = "1.36.0")]
1822
pub struct RawWaker {
@@ -355,8 +359,12 @@ impl<'a> ContextBuilder<'a> {
355359
/// of `*waker = new_waker.clone()`, as the former will avoid cloning the waker
356360
/// unnecessarily if the two wakers [wake the same task](Self::will_wake).
357361
///
362+
/// Constructing a `Waker` from a [`RawWaker`] is unsafe.
363+
/// Implementing the [`Wake`] trait is a safe alternative that requires memory allocation.
364+
///
358365
/// [`Future::poll()`]: core::future::Future::poll
359366
/// [`Poll::Pending`]: core::task::Poll::Pending
367+
/// [`Wake`]: ../../alloc/task/trait.Wake.html
360368
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/66401
361369
#[stable(feature = "futures_api", since = "1.36.0")]
362370
pub struct Waker {
@@ -438,9 +446,15 @@ impl Waker {
438446

439447
/// Creates a new `Waker` from [`RawWaker`].
440448
///
449+
/// # Safety
450+
///
441451
/// The behavior of the returned `Waker` is undefined if the contract defined
442452
/// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
443-
/// Therefore this method is unsafe.
453+
///
454+
/// (Authors wishing to avoid unsafe code may implement the [`Wake`] trait instead, at the
455+
/// cost of a required heap allocation.)
456+
///
457+
/// [`Wake`]: ../../alloc/task/trait.Wake.html
444458
#[inline]
445459
#[must_use]
446460
#[stable(feature = "futures_api", since = "1.36.0")]

std/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ fn main() {
77
let target_vendor =
88
env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
99
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
10-
10+
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
11+
println!("cargo:rustc-cfg=netbsd10");
12+
}
1113
if target_os == "linux"
1214
|| target_os == "android"
1315
|| target_os == "netbsd"

std/src/sync/once_lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::sync::Once;
1313
///
1414
/// # Examples
1515
///
16-
/// Using `OnceCell` to store a function’s previously computed value (a.k.a.
16+
/// Using `OnceLock` to store a function’s previously computed value (a.k.a.
1717
/// ‘lazy static’ or ‘memoizing’):
1818
///
1919
/// ```

std/src/sys/pal/unix/rand.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod imp {
6262
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
6363
}
6464

65-
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd"))]
65+
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd", netbsd10))]
6666
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
6767
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
6868
}
@@ -72,7 +72,8 @@ mod imp {
7272
target_os = "android",
7373
target_os = "espidf",
7474
target_os = "horizon",
75-
target_os = "freebsd"
75+
target_os = "freebsd",
76+
netbsd10
7677
)))]
7778
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
7879
false
@@ -83,7 +84,8 @@ mod imp {
8384
target_os = "android",
8485
target_os = "espidf",
8586
target_os = "horizon",
86-
target_os = "freebsd"
87+
target_os = "freebsd",
88+
netbsd10
8789
))]
8890
fn getrandom_fill_bytes(v: &mut [u8]) -> bool {
8991
use crate::sync::atomic::{AtomicBool, Ordering};
@@ -230,7 +232,7 @@ mod imp {
230232
}
231233

232234
// FIXME: once the 10.x release becomes the minimum, this can be dropped for simplification.
233-
#[cfg(target_os = "netbsd")]
235+
#[cfg(all(target_os = "netbsd", not(netbsd10)))]
234236
mod imp {
235237
use crate::ptr;
236238

0 commit comments

Comments
 (0)