Skip to content

Commit 492e57c

Browse files
committedNov 9, 2023
Auto merge of #117736 - TaKO8Ki:rollup-fjrtmlb, r=TaKO8Ki
Rollup of 6 pull requests Successful merges: - #116762 (Fixup `Atomic*::from_ptr` safety docs) - #117645 (Extend builtin/auto trait args with error when they have >1 argument) - #117694 (Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`) - #117705 (triagebot.toml: use inclusive language) - #117723 (speed up `x clean`) - #117724 (Restore rustc shim error message) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d8dbf7c + f5195c5 commit 492e57c

File tree

18 files changed

+152
-74
lines changed

18 files changed

+152
-74
lines changed
 

‎compiler/rustc_span/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2525
#![feature(array_windows)]
2626
#![feature(cfg_match)]
27+
#![feature(core_io_borrowed_buf)]
2728
#![feature(if_let_guard)]
2829
#![feature(let_chains)]
2930
#![feature(min_specialization)]

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -2389,12 +2389,21 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
23892389
)
23902390
});
23912391

2392-
let obligation = Obligation::new(
2393-
self.tcx(),
2394-
cause.clone(),
2395-
param_env,
2396-
ty::TraitRef::new(self.tcx(), trait_def_id, [normalized_ty]),
2397-
);
2392+
let tcx = self.tcx();
2393+
let trait_ref = if tcx.generics_of(trait_def_id).params.len() == 1 {
2394+
ty::TraitRef::new(tcx, trait_def_id, [normalized_ty])
2395+
} else {
2396+
// If this is an ill-formed auto/built-in trait, then synthesize
2397+
// new error args for the missing generics.
2398+
let err_args = ty::GenericArgs::extend_with_error(
2399+
tcx,
2400+
trait_def_id,
2401+
&[normalized_ty.into()],
2402+
);
2403+
ty::TraitRef::new(tcx, trait_def_id, err_args)
2404+
};
2405+
2406+
let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref);
23982407
obligations.push(obligation);
23992408
obligations
24002409
})

‎library/std/src/io/readbuf.rs ‎library/core/src/io/borrowed_buf.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
#![unstable(feature = "read_buf", issue = "78485")]
2-
3-
#[cfg(test)]
4-
mod tests;
1+
#![unstable(feature = "core_io_borrowed_buf", issue = "117693")]
52

63
use crate::fmt::{self, Debug, Formatter};
7-
use crate::io::{Result, Write};
84
use crate::mem::{self, MaybeUninit};
95
use crate::{cmp, ptr};
106

@@ -303,16 +299,3 @@ impl<'a> BorrowedCursor<'a> {
303299
self.buf.filled += buf.len();
304300
}
305301
}
306-
307-
impl<'a> Write for BorrowedCursor<'a> {
308-
fn write(&mut self, buf: &[u8]) -> Result<usize> {
309-
let amt = cmp::min(buf.len(), self.capacity());
310-
self.append(&buf[..amt]);
311-
Ok(amt)
312-
}
313-
314-
#[inline]
315-
fn flush(&mut self) -> Result<()> {
316-
Ok(())
317-
}
318-
}

‎library/core/src/io/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Traits, helpers, and type definitions for core I/O functionality.
2+
3+
mod borrowed_buf;
4+
5+
#[unstable(feature = "core_io_borrowed_buf", issue = "117693")]
6+
pub use self::borrowed_buf::{BorrowedBuf, BorrowedCursor};

‎library/core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ pub mod async_iter;
369369
pub mod cell;
370370
pub mod char;
371371
pub mod ffi;
372+
#[unstable(feature = "core_io_borrowed_buf", issue = "117693")]
373+
pub mod io;
372374
pub mod iter;
373375
pub mod net;
374376
pub mod option;

‎library/core/src/sync/atomic.rs

+81-43
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,12 @@
44
//! threads, and are the building blocks of other concurrent
55
//! types.
66
//!
7-
//! Rust atomics currently follow the same rules as [C++20 atomics][cpp], specifically `atomic_ref`.
8-
//! Basically, creating a *shared reference* to one of the Rust atomic types corresponds to creating
9-
//! an `atomic_ref` in C++; the `atomic_ref` is destroyed when the lifetime of the shared reference
10-
//! ends. (A Rust atomic type that is exclusively owned or behind a mutable reference does *not*
11-
//! correspond to an "atomic object" in C++, since it can be accessed via non-atomic operations.)
12-
//!
137
//! This module defines atomic versions of a select number of primitive
148
//! types, including [`AtomicBool`], [`AtomicIsize`], [`AtomicUsize`],
159
//! [`AtomicI8`], [`AtomicU16`], etc.
1610
//! Atomic types present operations that, when used correctly, synchronize
1711
//! updates between threads.
1812
//!
19-
//! Each method takes an [`Ordering`] which represents the strength of
20-
//! the memory barrier for that operation. These orderings are the
21-
//! same as the [C++20 atomic orderings][1]. For more information see the [nomicon][2].
22-
//!
23-
//! [cpp]: https://en.cppreference.com/w/cpp/atomic
24-
//! [1]: https://en.cppreference.com/w/cpp/atomic/memory_order
25-
//! [2]: ../../../nomicon/atomics.html
26-
//!
2713
//! Atomic variables are safe to share between threads (they implement [`Sync`])
2814
//! but they do not themselves provide the mechanism for sharing and follow the
2915
//! [threading model](../../../std/thread/index.html#the-threading-model) of Rust.
@@ -36,6 +22,75 @@
3622
//! the constant initializers like [`AtomicBool::new`]. Atomic statics
3723
//! are often used for lazy global initialization.
3824
//!
25+
//! ## Memory model for atomic accesses
26+
//!
27+
//! Rust atomics currently follow the same rules as [C++20 atomics][cpp], specifically `atomic_ref`.
28+
//! Basically, creating a *shared reference* to one of the Rust atomic types corresponds to creating
29+
//! an `atomic_ref` in C++; the `atomic_ref` is destroyed when the lifetime of the shared reference
30+
//! ends. (A Rust atomic type that is exclusively owned or behind a mutable reference does *not*
31+
//! correspond to an "atomic object" in C++, since it can be accessed via non-atomic operations.)
32+
//!
33+
//! [cpp]: https://en.cppreference.com/w/cpp/atomic
34+
//!
35+
//! Each method takes an [`Ordering`] which represents the strength of
36+
//! the memory barrier for that operation. These orderings are the
37+
//! same as the [C++20 atomic orderings][1]. For more information see the [nomicon][2].
38+
//!
39+
//! [1]: https://en.cppreference.com/w/cpp/atomic/memory_order
40+
//! [2]: ../../../nomicon/atomics.html
41+
//!
42+
//! Since C++ does not support mixing atomic and non-atomic accesses, or non-synchronized
43+
//! different-sized accesses to the same data, Rust does not support those operations either.
44+
//! Note that both of those restrictions only apply if the accesses are non-synchronized.
45+
//!
46+
//! ```rust,no_run undefined_behavior
47+
//! use std::sync::atomic::{AtomicU16, AtomicU8, Ordering};
48+
//! use std::mem::transmute;
49+
//! use std::thread;
50+
//!
51+
//! let atomic = AtomicU16::new(0);
52+
//!
53+
//! thread::scope(|s| {
54+
//! // This is UB: mixing atomic and non-atomic accesses
55+
//! s.spawn(|| atomic.store(1, Ordering::Relaxed));
56+
//! s.spawn(|| unsafe { atomic.as_ptr().write(2) });
57+
//! });
58+
//!
59+
//! thread::scope(|s| {
60+
//! // This is UB: even reads are not allowed to be mixed
61+
//! s.spawn(|| atomic.load(Ordering::Relaxed));
62+
//! s.spawn(|| unsafe { atomic.as_ptr().read() });
63+
//! });
64+
//!
65+
//! thread::scope(|s| {
66+
//! // This is fine, `join` synchronizes the code in a way such that atomic
67+
//! // and non-atomic accesses can't happen "at the same time"
68+
//! let handle = s.spawn(|| atomic.store(1, Ordering::Relaxed));
69+
//! handle.join().unwrap();
70+
//! s.spawn(|| unsafe { atomic.as_ptr().write(2) });
71+
//! });
72+
//!
73+
//! thread::scope(|s| {
74+
//! // This is UB: using different-sized atomic accesses to the same data
75+
//! s.spawn(|| atomic.store(1, Ordering::Relaxed));
76+
//! s.spawn(|| unsafe {
77+
//! let differently_sized = transmute::<&AtomicU16, &AtomicU8>(&atomic);
78+
//! differently_sized.store(2, Ordering::Relaxed);
79+
//! });
80+
//! });
81+
//!
82+
//! thread::scope(|s| {
83+
//! // This is fine, `join` synchronizes the code in a way such that
84+
//! // differently-sized accesses can't happen "at the same time"
85+
//! let handle = s.spawn(|| atomic.store(1, Ordering::Relaxed));
86+
//! handle.join().unwrap();
87+
//! s.spawn(|| unsafe {
88+
//! let differently_sized = transmute::<&AtomicU16, &AtomicU8>(&atomic);
89+
//! differently_sized.store(2, Ordering::Relaxed);
90+
//! });
91+
//! });
92+
//! ```
93+
//!
3994
//! # Portability
4095
//!
4196
//! All atomic types in this module are guaranteed to be [lock-free] if they're
@@ -383,16 +438,12 @@ impl AtomicBool {
383438
/// * `ptr` must be aligned to `align_of::<AtomicBool>()` (note that on some platforms this can
384439
/// be bigger than `align_of::<bool>()`).
385440
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
386-
/// * Non-atomic accesses to the value behind `ptr` must have a happens-before relationship
387-
/// with atomic accesses via the returned value (or vice-versa).
388-
/// * In other words, time periods where the value is accessed atomically may not overlap
389-
/// with periods where the value is accessed non-atomically.
390-
/// * This requirement is trivially satisfied if `ptr` is never used non-atomically for the
391-
/// duration of lifetime `'a`. Most use cases should be able to follow this guideline.
392-
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are done
393-
/// from the same thread.
441+
/// * You must adhere to the [Memory model for atomic accesses]. In particular, it is not
442+
/// allowed to mix atomic and non-atomic accesses, or atomic accesses of different sizes,
443+
/// without synchronization.
394444
///
395445
/// [valid]: crate::ptr#safety
446+
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
396447
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")]
397448
#[rustc_const_unstable(feature = "const_atomic_from_ptr", issue = "108652")]
398449
pub const unsafe fn from_ptr<'a>(ptr: *mut bool) -> &'a AtomicBool {
@@ -1185,18 +1236,12 @@ impl<T> AtomicPtr<T> {
11851236
/// * `ptr` must be aligned to `align_of::<AtomicPtr<T>>()` (note that on some platforms this
11861237
/// can be bigger than `align_of::<*mut T>()`).
11871238
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
1188-
/// * Non-atomic accesses to the value behind `ptr` must have a happens-before relationship
1189-
/// with atomic accesses via the returned value (or vice-versa).
1190-
/// * In other words, time periods where the value is accessed atomically may not overlap
1191-
/// with periods where the value is accessed non-atomically.
1192-
/// * This requirement is trivially satisfied if `ptr` is never used non-atomically for the
1193-
/// duration of lifetime `'a`. Most use cases should be able to follow this guideline.
1194-
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are done
1195-
/// from the same thread.
1196-
/// * This method should not be used to create overlapping or mixed-size atomic accesses, as
1197-
/// these are not supported by the memory model.
1239+
/// * You must adhere to the [Memory model for atomic accesses]. In particular, it is not
1240+
/// allowed to mix atomic and non-atomic accesses, or atomic accesses of different sizes,
1241+
/// without synchronization.
11981242
///
11991243
/// [valid]: crate::ptr#safety
1244+
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
12001245
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")]
12011246
#[rustc_const_unstable(feature = "const_atomic_from_ptr", issue = "108652")]
12021247
pub const unsafe fn from_ptr<'a>(ptr: *mut *mut T) -> &'a AtomicPtr<T> {
@@ -2167,19 +2212,12 @@ macro_rules! atomic_int {
21672212
`align_of::<", stringify!($atomic_type), ">()` (note that on some platforms this \
21682213
can be bigger than `align_of::<", stringify!($int_type), ">()`).")]
21692214
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
2170-
/// * Non-atomic accesses to the value behind `ptr` must have a happens-before
2171-
/// relationship with atomic accesses via the returned value (or vice-versa).
2172-
/// * In other words, time periods where the value is accessed atomically may not
2173-
/// overlap with periods where the value is accessed non-atomically.
2174-
/// * This requirement is trivially satisfied if `ptr` is never used non-atomically
2175-
/// for the duration of lifetime `'a`. Most use cases should be able to follow
2176-
/// this guideline.
2177-
/// * This requirement is also trivially satisfied if all accesses (atomic or not) are
2178-
/// done from the same thread.
2179-
/// * This method should not be used to create overlapping or mixed-size atomic
2180-
/// accesses, as these are not supported by the memory model.
2215+
/// * You must adhere to the [Memory model for atomic accesses]. In particular, it is not
2216+
/// allowed to mix atomic and non-atomic accesses, or atomic accesses of different sizes,
2217+
/// without synchronization.
21812218
///
21822219
/// [valid]: crate::ptr#safety
2220+
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
21832221
#[stable(feature = "atomic_from_ptr", since = "CURRENT_RUSTC_VERSION")]
21842222
#[rustc_const_unstable(feature = "const_atomic_from_ptr", issue = "108652")]
21852223
pub const unsafe fn from_ptr<'a>(ptr: *mut $int_type) -> &'a $atomic_type {

‎library/std/src/io/readbuf/tests.rs ‎library/core/tests/io/borrowed_buf.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use super::BorrowedBuf;
2-
use crate::mem::MaybeUninit;
1+
use core::io::BorrowedBuf;
2+
use core::mem::MaybeUninit;
33

44
/// Test that BorrowedBuf has the correct numbers when created with new
55
#[test]

‎library/core/tests/io/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod borrowed_buf;

‎library/core/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(const_likely)]
2424
#![feature(const_location_fields)]
2525
#![feature(core_intrinsics)]
26+
#![feature(core_io_borrowed_buf)]
2627
#![feature(core_private_bignum)]
2728
#![feature(core_private_diy_float)]
2829
#![feature(dec2flt)]
@@ -135,6 +136,7 @@ mod fmt;
135136
mod future;
136137
mod hash;
137138
mod intrinsics;
139+
mod io;
138140
mod iter;
139141
mod lazy;
140142
#[cfg(test)]

‎library/std/src/io/impls.rs

+14
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,17 @@ impl<A: Allocator> Write for VecDeque<u8, A> {
528528
Ok(())
529529
}
530530
}
531+
532+
#[unstable(feature = "read_buf", issue = "78485")]
533+
impl<'a> io::Write for core::io::BorrowedCursor<'a> {
534+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
535+
let amt = cmp::min(buf.len(), self.capacity());
536+
self.append(&buf[..amt]);
537+
Ok(amt)
538+
}
539+
540+
#[inline]
541+
fn flush(&mut self) -> io::Result<()> {
542+
Ok(())
543+
}
544+
}

‎library/std/src/io/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ pub use self::{
330330
};
331331

332332
#[unstable(feature = "read_buf", issue = "78485")]
333-
pub use self::readbuf::{BorrowedBuf, BorrowedCursor};
333+
pub use core::io::{BorrowedBuf, BorrowedCursor};
334334
pub(crate) use error::const_io_error;
335335

336336
mod buffered;
@@ -339,7 +339,6 @@ mod cursor;
339339
mod error;
340340
mod impls;
341341
pub mod prelude;
342-
mod readbuf;
343342
mod stdio;
344343
mod util;
345344

‎library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310
// tidy-alphabetical-start
311311
#![feature(char_internals)]
312312
#![feature(core_intrinsics)]
313+
#![feature(core_io_borrowed_buf)]
313314
#![feature(duration_constants)]
314315
#![feature(error_generic_member_access)]
315316
#![feature(error_in_core)]

‎src/bootstrap/src/bin/rustc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ fn main() {
3232
let args = env::args_os().skip(1).collect::<Vec<_>>();
3333
let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
3434

35+
// We don't use the stage in this shim, but let's parse it to make sure that we're invoked
36+
// by bootstrap, or that we provide a helpful error message if not.
37+
bin_helpers::parse_rustc_stage();
3538
let verbose = bin_helpers::parse_rustc_verbose();
3639

3740
// Detect whether or not we're a build script depending on whether --target

‎src/bootstrap/src/core/build_steps/clean.rs

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ fn clean_specific_stage(build: &Build, stage: u32) {
139139
fn clean_default(build: &Build) {
140140
rm_rf(&build.out.join("tmp"));
141141
rm_rf(&build.out.join("dist"));
142-
rm_rf(&build.out.join("bootstrap"));
143142
rm_rf(&build.out.join("rustfmt.stamp"));
144143

145144
for host in &build.hosts {

‎src/bootstrap/src/utils/bin_helpers.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub(crate) fn parse_rustc_verbose() -> usize {
1818
/// Parses the value of the "RUSTC_STAGE" environment variable and returns it as a `String`.
1919
///
2020
/// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
21-
#[allow(unused)]
2221
pub(crate) fn parse_rustc_stage() -> String {
2322
std::env::var("RUSTC_STAGE").unwrap_or_else(|_| {
2423
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.

‎tests/ui/auto-traits/has-arguments.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(auto_traits)]
2+
3+
auto trait Trait1<'outer> {}
4+
//~^ ERROR auto traits cannot have generic parameters
5+
6+
fn f<'a>(x: impl Trait1<'a>) {}
7+
8+
fn main() {
9+
f("");
10+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0567]: auto traits cannot have generic parameters
2+
--> $DIR/has-arguments.rs:3:18
3+
|
4+
LL | auto trait Trait1<'outer> {}
5+
| ------^^^^^^^^ help: remove the parameters
6+
| |
7+
| auto trait cannot have generic parameters
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0567`.

‎triagebot.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ Otherwise, you can ignore this comment.
579579
message = "`src/tools/x` was changed. Bump version of Cargo.toml in `src/tools/x` so tidy will suggest installing the new version."
580580

581581
[mentions."src/tools/tidy/src/deps.rs"]
582-
message = "Third-party dependency whitelist may have been modified! You must ensure that any new dependencies have compatible licenses before merging."
582+
message = "The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging."
583583
cc = ["@davidtwco", "@wesleywiser"]
584584

585585
[mentions."src/bootstrap/src/core/config"]

0 commit comments

Comments
 (0)
Please sign in to comment.