Skip to content

Commit ed17ada

Browse files
committed
Merge from rustc
2 parents 74c2b16 + 10446e7 commit ed17ada

File tree

14 files changed

+177
-61
lines changed

14 files changed

+177
-61
lines changed

alloc/src/fmt.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@
278278
//! Hello, ` 123` has 3 right-aligned characters
279279
//! ```
280280
//!
281+
//! When truncating these values, Rust uses [round half-to-even](https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even),
282+
//! which is the default rounding mode in IEEE 754.
283+
//! For example,
284+
//!
285+
//! ```
286+
//! print!("{0:.1$e}", 12345, 3);
287+
//! print!("{0:.1$e}", 12355, 3);
288+
//! ```
289+
//!
290+
//! Would return:
291+
//!
292+
//! ```text
293+
//! 1.234e4
294+
//! 1.236e4
295+
//! ```
296+
//!
281297
//! ## Localization
282298
//!
283299
//! In some programming languages, the behavior of string formatting functions

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/iter/traits/iterator.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ pub trait Iterator {
8989
///
9090
/// # Examples
9191
///
92-
/// Basic usage:
93-
///
9492
/// ```
9593
/// let a = [1, 2, 3];
9694
///
@@ -249,8 +247,6 @@ pub trait Iterator {
249247
///
250248
/// # Examples
251249
///
252-
/// Basic usage:
253-
///
254250
/// ```
255251
/// let a = [1, 2, 3];
256252
/// assert_eq!(a.iter().count(), 3);
@@ -280,8 +276,6 @@ pub trait Iterator {
280276
///
281277
/// # Examples
282278
///
283-
/// Basic usage:
284-
///
285279
/// ```
286280
/// let a = [1, 2, 3];
287281
/// assert_eq!(a.iter().last(), Some(&3));
@@ -324,8 +318,6 @@ pub trait Iterator {
324318
///
325319
/// # Examples
326320
///
327-
/// Basic usage:
328-
///
329321
/// ```
330322
/// #![feature(iter_advance_by)]
331323
///
@@ -432,8 +424,6 @@ pub trait Iterator {
432424
///
433425
/// # Examples
434426
///
435-
/// Basic usage:
436-
///
437427
/// ```
438428
/// let a = [0, 1, 2, 3, 4, 5];
439429
/// let mut iter = a.iter().step_by(2);
@@ -1342,8 +1332,6 @@ pub trait Iterator {
13421332
///
13431333
/// # Examples
13441334
///
1345-
/// Basic usage:
1346-
///
13471335
/// ```
13481336
/// let a = [1, 2, 3];
13491337
///
@@ -1434,8 +1422,6 @@ pub trait Iterator {
14341422
///
14351423
/// # Examples
14361424
///
1437-
/// Basic usage:
1438-
///
14391425
/// ```
14401426
/// let a = [1, 2, 3, 4];
14411427
///
@@ -1486,8 +1472,6 @@ pub trait Iterator {
14861472
///
14871473
/// # Examples
14881474
///
1489-
/// Basic usage:
1490-
///
14911475
/// ```
14921476
/// let words = ["alpha", "beta", "gamma"];
14931477
///
@@ -1765,8 +1749,6 @@ pub trait Iterator {
17651749
///
17661750
/// # Examples
17671751
///
1768-
/// Basic usage:
1769-
///
17701752
/// ```
17711753
/// // an iterator which alternates between Some and None
17721754
/// struct Alternate {
@@ -1911,8 +1893,6 @@ pub trait Iterator {
19111893
///
19121894
/// # Examples
19131895
///
1914-
/// Basic usage:
1915-
///
19161896
/// ```
19171897
/// let mut words = ["hello", "world", "of", "Rust"].into_iter();
19181898
///
@@ -2221,8 +2201,6 @@ pub trait Iterator {
22212201
///
22222202
/// # Examples
22232203
///
2224-
/// Basic usage:
2225-
///
22262204
/// ```
22272205
/// let a = [1, 2, 3];
22282206
///
@@ -3193,8 +3171,6 @@ pub trait Iterator {
31933171
///
31943172
/// # Examples
31953173
///
3196-
/// Basic usage:
3197-
///
31983174
/// ```
31993175
/// let a = [1, 2, 3];
32003176
/// let b: Vec<u32> = Vec::new();
@@ -3232,8 +3208,6 @@ pub trait Iterator {
32323208
///
32333209
/// # Examples
32343210
///
3235-
/// Basic usage:
3236-
///
32373211
/// ```
32383212
/// let a = [1, 2, 3];
32393213
/// let b: Vec<u32> = Vec::new();
@@ -3420,8 +3394,6 @@ pub trait Iterator {
34203394
///
34213395
/// # Examples
34223396
///
3423-
/// Basic usage:
3424-
///
34253397
/// ```
34263398
/// let a = [(1, 2), (3, 4), (5, 6)];
34273399
///
@@ -3458,8 +3430,6 @@ pub trait Iterator {
34583430
///
34593431
/// # Examples
34603432
///
3461-
/// Basic usage:
3462-
///
34633433
/// ```
34643434
/// let a = [1, 2, 3];
34653435
///
@@ -3538,8 +3508,6 @@ pub trait Iterator {
35383508
///
35393509
/// # Examples
35403510
///
3541-
/// Basic usage:
3542-
///
35433511
/// ```
35443512
/// let a = [1, 2, 3];
35453513
///
@@ -3624,8 +3592,6 @@ pub trait Iterator {
36243592
///
36253593
/// # Examples
36263594
///
3627-
/// Basic usage:
3628-
///
36293595
/// ```
36303596
/// let a = [1, 2, 3];
36313597
/// let sum: i32 = a.iter().sum();
@@ -3703,8 +3669,6 @@ pub trait Iterator {
37033669
///
37043670
/// # Examples
37053671
///
3706-
/// Basic usage:
3707-
///
37083672
/// ```
37093673
/// #![feature(iter_order_by)]
37103674
///
@@ -3790,8 +3754,6 @@ pub trait Iterator {
37903754
///
37913755
/// # Examples
37923756
///
3793-
/// Basic usage:
3794-
///
37953757
/// ```
37963758
/// #![feature(iter_order_by)]
37973759
///
@@ -3863,8 +3825,6 @@ pub trait Iterator {
38633825
///
38643826
/// # Examples
38653827
///
3866-
/// Basic usage:
3867-
///
38683828
/// ```
38693829
/// #![feature(iter_order_by)]
38703830
///

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/process.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub struct Child {
171171
/// The handle for writing to the child's standard input (stdin), if it
172172
/// has been captured. You might find it helpful to do
173173
///
174-
/// ```compile_fail,E0425
174+
/// ```ignore (incomplete)
175175
/// let stdin = child.stdin.take().unwrap();
176176
/// ```
177177
///
@@ -183,7 +183,7 @@ pub struct Child {
183183
/// The handle for reading from the child's standard output (stdout), if it
184184
/// has been captured. You might find it helpful to do
185185
///
186-
/// ```compile_fail,E0425
186+
/// ```ignore (incomplete)
187187
/// let stdout = child.stdout.take().unwrap();
188188
/// ```
189189
///
@@ -195,7 +195,7 @@ pub struct Child {
195195
/// The handle for reading from the child's standard error (stderr), if it
196196
/// has been captured. You might find it helpful to do
197197
///
198-
/// ```compile_fail,E0425
198+
/// ```ignore (incomplete)
199199
/// let stderr = child.stderr.take().unwrap();
200200
/// ```
201201
///

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
/// ```

0 commit comments

Comments
 (0)