Skip to content

Commit 1edd389

Browse files
committed
Auto merge of rust-lang#70330 - Centril:rollup-ts0clvx, r=Centril
Rollup of 9 pull requests Successful merges: - rust-lang#68700 (Add Wake trait for safe construction of Wakers.) - rust-lang#69494 (Stabilize --crate-version option in rustdoc) - rust-lang#70080 (rustc_mir: remove extra space when pretty-printing MIR.) - rust-lang#70195 (Add test for issue rust-lang#53275) - rust-lang#70199 (Revised span-to-lines conversion to produce an empty vec on DUMMY_SP.) - rust-lang#70299 (add err_machine_stop macro) - rust-lang#70300 (Reword unused variable warning) - rust-lang#70315 (Rename remaining occurences of Void to Opaque.) - rust-lang#70318 (Split long derive lists into two derive attributes.) Failed merges: r? @ghost
2 parents 55299b2 + 5b29348 commit 1edd389

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+296
-586
lines changed

src/bootstrap/bin/rustdoc.rs

-5
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ fn main() {
5252
// Bootstrap's Cargo-command builder sets this variable to the current Rust version; let's pick
5353
// it up so we can make rustdoc print this into the docs
5454
if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
55-
// This "unstable-options" can be removed when `--crate-version` is stabilized
56-
if !has_unstable {
57-
cmd.arg("-Z").arg("unstable-options");
58-
}
5955
cmd.arg("--crate-version").arg(version);
60-
has_unstable = true;
6156
}
6257

6358
// Needed to be able to run all rustdoc tests.

src/bootstrap/doc.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ impl Step for Standalone {
313313
}
314314

315315
let mut cmd = builder.rustdoc_cmd(compiler);
316+
// Needed for --index-page flag
317+
cmd.arg("-Z").arg("unstable-options");
318+
316319
cmd.arg("--html-after-content")
317320
.arg(&footer)
318321
.arg("--html-before-content")
@@ -395,7 +398,7 @@ impl Step for Std {
395398

396399
// Keep a whitelist so we do not build internal stdlib crates, these will be
397400
// build by the rustc step later if enabled.
398-
cargo.arg("-Z").arg("unstable-options").arg("-p").arg(package);
401+
cargo.arg("-p").arg(package);
399402
// Create all crate output directories first to make sure rustdoc uses
400403
// relative links.
401404
// FIXME: Cargo should probably do this itself.
@@ -406,6 +409,8 @@ impl Step for Std {
406409
.arg("rust.css")
407410
.arg("--markdown-no-toc")
408411
.arg("--generate-redirect-pages")
412+
.arg("-Z")
413+
.arg("unstable-options")
409414
.arg("--resource-suffix")
410415
.arg(crate::channel::CFG_RELEASE_NUM)
411416
.arg("--index-page")

src/doc/rustc/src/json.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Diagnostics have the following format:
168168
"rendered": null
169169
},
170170
{
171-
"message": "consider prefixing with an underscore",
171+
"message": "if this is intentional, prefix it with an underscore",
172172
"code": null,
173173
"level": "help",
174174
"spans": [
@@ -201,7 +201,7 @@ Diagnostics have the following format:
201201
/* Optional string of the rendered version of the diagnostic as displayed
202202
by rustc. Note that this may be influenced by the `--json` flag.
203203
*/
204-
"rendered": "warning: unused variable: `x`\n --> lib.rs:2:9\n |\n2 | let x = 123;\n | ^ help: consider prefixing with an underscore: `_x`\n |\n = note: `#[warn(unused_variables)]` on by default\n\n"
204+
"rendered": "warning: unused variable: `x`\n --> lib.rs:2:9\n |\n2 | let x = 123;\n | ^ help: if this is intentional, prefix it with an underscore: `_x`\n |\n = note: `#[warn(unused_variables)]` on by default\n\n"
205205
}
206206
```
207207

src/doc/rustdoc/src/command-line-arguments.md

+12
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,15 @@ the same CSS rules as the official `light` theme.
390390
`--check-theme` is a separate mode in `rustdoc`. When `rustdoc` sees the
391391
`--check-theme` flag, it discards all other flags and only performs the CSS rule
392392
comparison operation.
393+
394+
### `--crate-version`: control the crate version
395+
396+
Using this flag looks like this:
397+
398+
```bash
399+
$ rustdoc src/lib.rs --crate-version 1.3.37
400+
```
401+
402+
When `rustdoc` receives this flag, it will print an extra "Version (version)" into the sidebar of
403+
the crate root's docs. You can use this flag to differentiate between different versions of your
404+
library's documentation.

src/doc/rustdoc/src/unstable-features.md

-12
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,6 @@ Markdown file, the URL given to `--markdown-playground-url` will take precedence
248248
`--playground-url` and `#![doc(html_playground_url = "url")]` are present when rendering crate docs,
249249
the attribute will take precedence.
250250

251-
### `--crate-version`: control the crate version
252-
253-
Using this flag looks like this:
254-
255-
```bash
256-
$ rustdoc src/lib.rs -Z unstable-options --crate-version 1.3.37
257-
```
258-
259-
When `rustdoc` receives this flag, it will print an extra "Version (version)" into the sidebar of
260-
the crate root's docs. You can use this flag to differentiate between different versions of your
261-
library's documentation.
262-
263251
### `--sort-modules-by-appearance`: control how items on module pages are sorted
264252

265253
Using this flag looks like this:

src/liballoc/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ pub mod str;
161161
pub mod string;
162162
#[cfg(target_has_atomic = "ptr")]
163163
pub mod sync;
164+
#[cfg(target_has_atomic = "ptr")]
165+
pub mod task;
164166
#[cfg(test)]
165167
mod tests;
166168
pub mod vec;

src/liballoc/task.rs

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#![unstable(feature = "wake_trait", issue = "69912")]
2+
//! Types and Traits for working with asynchronous tasks.
3+
use core::mem::{self, ManuallyDrop};
4+
use core::task::{RawWaker, RawWakerVTable, Waker};
5+
6+
use crate::sync::Arc;
7+
8+
/// The implementation of waking a task on an executor.
9+
///
10+
/// This trait can be used to create a [`Waker`]. An executor can define an
11+
/// implementation of this trait, and use that to construct a Waker to pass
12+
/// to the tasks that are executed on that executor.
13+
///
14+
/// This trait is a memory-safe and ergonomic alternative to constructing a
15+
/// [`RawWaker`]. It supports the common executor design in which the data
16+
/// used to wake up a task is stored in an [`Arc`]. Some executors (especially
17+
/// those for embedded systems) cannot use this API, which is why [`RawWaker`]
18+
/// exists as an alternative for those systems.
19+
#[unstable(feature = "wake_trait", issue = "69912")]
20+
pub trait Wake {
21+
/// Wake this task.
22+
#[unstable(feature = "wake_trait", issue = "69912")]
23+
fn wake(self: Arc<Self>);
24+
25+
/// Wake this task without consuming the waker.
26+
///
27+
/// If an executor supports a cheaper way to wake without consuming the
28+
/// waker, it should override this method. By default, it clones the
29+
/// [`Arc`] and calls `wake` on the clone.
30+
#[unstable(feature = "wake_trait", issue = "69912")]
31+
fn wake_by_ref(self: &Arc<Self>) {
32+
self.clone().wake();
33+
}
34+
}
35+
36+
#[unstable(feature = "wake_trait", issue = "69912")]
37+
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
38+
fn from(waker: Arc<W>) -> Waker {
39+
// SAFETY: This is safe because raw_waker safely constructs
40+
// a RawWaker from Arc<W>.
41+
unsafe { Waker::from_raw(raw_waker(waker)) }
42+
}
43+
}
44+
45+
#[unstable(feature = "wake_trait", issue = "69912")]
46+
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
47+
fn from(waker: Arc<W>) -> RawWaker {
48+
raw_waker(waker)
49+
}
50+
}
51+
52+
// NB: This private function for constructing a RawWaker is used, rather than
53+
// inlining this into the `From<Arc<W>> for RawWaker` impl, to ensure that
54+
// the safety of `From<Arc<W>> for Waker` does not depend on the correct
55+
// trait dispatch - instead both impls call this function directly and
56+
// explicitly.
57+
#[inline(always)]
58+
fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
59+
// Increment the reference count of the arc to clone it.
60+
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
61+
let waker: Arc<W> = Arc::from_raw(waker as *const W);
62+
mem::forget(Arc::clone(&waker));
63+
raw_waker(waker)
64+
}
65+
66+
// Wake by value, moving the Arc into the Wake::wake function
67+
unsafe fn wake<W: Wake + Send + Sync + 'static>(waker: *const ()) {
68+
let waker: Arc<W> = Arc::from_raw(waker as *const W);
69+
<W as Wake>::wake(waker);
70+
}
71+
72+
// Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it
73+
unsafe fn wake_by_ref<W: Wake + Send + Sync + 'static>(waker: *const ()) {
74+
let waker: ManuallyDrop<Arc<W>> = ManuallyDrop::new(Arc::from_raw(waker as *const W));
75+
<W as Wake>::wake_by_ref(&waker);
76+
}
77+
78+
// Decrement the reference count of the Arc on drop
79+
unsafe fn drop_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) {
80+
mem::drop(Arc::from_raw(waker as *const W));
81+
}
82+
83+
RawWaker::new(
84+
Arc::into_raw(waker) as *const (),
85+
&RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
86+
)
87+
}

src/libcore/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ impl<'a> ArgumentV1<'a> {
282282
// SAFETY: `mem::transmute(x)` is safe because
283283
// 1. `&'b T` keeps the lifetime it originated with `'b`
284284
// (so as to not have an unbounded lifetime)
285-
// 2. `&'b T` and `&'b Void` have the same memory layout
285+
// 2. `&'b T` and `&'b Opaque` have the same memory layout
286286
// (when `T` is `Sized`, as it is here)
287287
// `mem::transmute(f)` is safe since `fn(&T, &mut Formatter<'_>) -> Result`
288-
// and `fn(&Void, &mut Formatter<'_>) -> Result` have the same ABI
288+
// and `fn(&Opaque, &mut Formatter<'_>) -> Result` have the same ABI
289289
// (as long as `T` is `Sized`)
290290
unsafe { ArgumentV1 { formatter: mem::transmute(f), value: mem::transmute(x) } }
291291
}

src/librustc/dep_graph/dep_node.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -489,19 +489,8 @@ impl<'tcx> DepNodeParams<'tcx> for HirId {
489489
/// some independent path or string that persists between runs without
490490
/// the need to be mapped or unmapped. (This ensures we can serialize
491491
/// them even in the absence of a tcx.)
492-
#[derive(
493-
Clone,
494-
Copy,
495-
Debug,
496-
PartialEq,
497-
Eq,
498-
PartialOrd,
499-
Ord,
500-
Hash,
501-
RustcEncodable,
502-
RustcDecodable,
503-
HashStable
504-
)]
492+
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
493+
#[derive(HashStable)]
505494
pub struct WorkProductId {
506495
hash: Fingerprint,
507496
}

src/librustc/middle/cstore.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,8 @@ impl CrateSource {
4040
}
4141
}
4242

43-
#[derive(
44-
RustcEncodable,
45-
RustcDecodable,
46-
Copy,
47-
Clone,
48-
Ord,
49-
PartialOrd,
50-
Eq,
51-
PartialEq,
52-
Debug,
53-
HashStable
54-
)]
43+
#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
44+
#[derive(HashStable)]
5545
pub enum DepKind {
5646
/// A dependency that is only used for its macros.
5747
MacrosOnly,

src/librustc/middle/region.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,8 @@ use std::fmt;
8080
// placate the same deriving in `ty::FreeRegion`, but we may want to
8181
// actually attach a more meaningful ordering to scopes than the one
8282
// generated via deriving here.
83-
#[derive(
84-
Clone,
85-
PartialEq,
86-
PartialOrd,
87-
Eq,
88-
Ord,
89-
Hash,
90-
Copy,
91-
RustcEncodable,
92-
RustcDecodable,
93-
HashStable
94-
)]
83+
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, RustcEncodable, RustcDecodable)]
84+
#[derive(HashStable)]
9585
pub struct Scope {
9686
pub id: hir::ItemLocalId,
9787
pub data: ScopeData,
@@ -114,19 +104,8 @@ impl fmt::Debug for Scope {
114104
}
115105
}
116106

117-
#[derive(
118-
Clone,
119-
PartialEq,
120-
PartialOrd,
121-
Eq,
122-
Ord,
123-
Hash,
124-
Debug,
125-
Copy,
126-
RustcEncodable,
127-
RustcDecodable,
128-
HashStable
129-
)]
107+
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)]
108+
#[derive(HashStable)]
130109
pub enum ScopeData {
131110
Node,
132111

src/librustc/mir/interpret/allocation.rs

+4-24
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,8 @@ use std::ops::{Deref, DerefMut, Range};
1515

1616
// NOTE: When adding new fields, make sure to adjust the `Snapshot` impl in
1717
// `src/librustc_mir/interpret/snapshot.rs`.
18-
#[derive(
19-
Clone,
20-
Debug,
21-
Eq,
22-
PartialEq,
23-
PartialOrd,
24-
Ord,
25-
Hash,
26-
RustcEncodable,
27-
RustcDecodable,
28-
HashStable
29-
)]
18+
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
19+
#[derive(HashStable)]
3020
pub struct Allocation<Tag = (), Extra = ()> {
3121
/// The actual bytes of the allocation.
3222
/// Note that the bytes of a pointer represent the offset of the pointer.
@@ -759,18 +749,8 @@ type Block = u64;
759749

760750
/// A bitmask where each bit refers to the byte with the same index. If the bit is `true`, the byte
761751
/// is defined. If it is `false` the byte is undefined.
762-
#[derive(
763-
Clone,
764-
Debug,
765-
Eq,
766-
PartialEq,
767-
PartialOrd,
768-
Ord,
769-
Hash,
770-
RustcEncodable,
771-
RustcDecodable,
772-
HashStable
773-
)]
752+
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
753+
#[derive(HashStable)]
774754
pub struct UndefMask {
775755
blocks: Vec<Block>,
776756
len: Size,

src/librustc/mir/interpret/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ macro_rules! err_exhaust {
4646
};
4747
}
4848

49+
#[macro_export]
50+
macro_rules! err_machine_stop {
51+
($($tt:tt)*) => {
52+
$crate::mir::interpret::InterpError::MachineStop(Box::new($($tt)*))
53+
};
54+
}
55+
4956
// In the `throw_*` macros, avoid `return` to make them work with `try {}`.
5057
#[macro_export]
5158
macro_rules! throw_unsup {
@@ -79,9 +86,7 @@ macro_rules! throw_exhaust {
7986

8087
#[macro_export]
8188
macro_rules! throw_machine_stop {
82-
($($tt:tt)*) => {
83-
Err::<!, _>($crate::mir::interpret::InterpError::MachineStop(Box::new($($tt)*)))?
84-
};
89+
($($tt:tt)*) => { Err::<!, _>(err_machine_stop!($($tt)*))? };
8590
}
8691

8792
mod allocation;

src/librustc/mir/interpret/pointer.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,8 @@ impl<T: layout::HasDataLayout> PointerArithmetic for T {}
111111
///
112112
/// `Pointer` is also generic over the `Tag` associated with each pointer,
113113
/// which is used to do provenance tracking during execution.
114-
#[derive(
115-
Copy,
116-
Clone,
117-
Eq,
118-
PartialEq,
119-
Ord,
120-
PartialOrd,
121-
RustcEncodable,
122-
RustcDecodable,
123-
Hash,
124-
HashStable
125-
)]
114+
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
115+
#[derive(HashStable)]
126116
pub struct Pointer<Tag = (), Id = AllocId> {
127117
pub alloc_id: Id,
128118
pub offset: Size,

0 commit comments

Comments
 (0)