Skip to content

Commit

Permalink
Auto merge of #70330 - Centril:rollup-ts0clvx, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #68700 (Add Wake trait for safe construction of Wakers.)
 - #69494 (Stabilize --crate-version option in rustdoc)
 - #70080 (rustc_mir: remove extra space when pretty-printing MIR.)
 - #70195 (Add test for issue #53275)
 - #70199 (Revised span-to-lines conversion to produce an empty vec on DUMMY_SP.)
 - #70299 (add err_machine_stop macro)
 - #70300 (Reword unused variable warning)
 - #70315 (Rename remaining occurences of Void to Opaque.)
 - #70318 (Split long derive lists into two derive attributes.)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Mar 23, 2020
2 parents 55299b2 + 5b29348 commit 1edd389
Show file tree
Hide file tree
Showing 56 changed files with 296 additions and 586 deletions.
5 changes: 0 additions & 5 deletions src/bootstrap/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ fn main() {
// Bootstrap's Cargo-command builder sets this variable to the current Rust version; let's pick
// it up so we can make rustdoc print this into the docs
if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
// This "unstable-options" can be removed when `--crate-version` is stabilized
if !has_unstable {
cmd.arg("-Z").arg("unstable-options");
}
cmd.arg("--crate-version").arg(version);
has_unstable = true;
}

// Needed to be able to run all rustdoc tests.
Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ impl Step for Standalone {
}

let mut cmd = builder.rustdoc_cmd(compiler);
// Needed for --index-page flag
cmd.arg("-Z").arg("unstable-options");

cmd.arg("--html-after-content")
.arg(&footer)
.arg("--html-before-content")
Expand Down Expand Up @@ -395,7 +398,7 @@ impl Step for Std {

// Keep a whitelist so we do not build internal stdlib crates, these will be
// build by the rustc step later if enabled.
cargo.arg("-Z").arg("unstable-options").arg("-p").arg(package);
cargo.arg("-p").arg(package);
// Create all crate output directories first to make sure rustdoc uses
// relative links.
// FIXME: Cargo should probably do this itself.
Expand All @@ -406,6 +409,8 @@ impl Step for Std {
.arg("rust.css")
.arg("--markdown-no-toc")
.arg("--generate-redirect-pages")
.arg("-Z")
.arg("unstable-options")
.arg("--resource-suffix")
.arg(crate::channel::CFG_RELEASE_NUM)
.arg("--index-page")
Expand Down
4 changes: 2 additions & 2 deletions src/doc/rustc/src/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Diagnostics have the following format:
"rendered": null
},
{
"message": "consider prefixing with an underscore",
"message": "if this is intentional, prefix it with an underscore",
"code": null,
"level": "help",
"spans": [
Expand Down Expand Up @@ -201,7 +201,7 @@ Diagnostics have the following format:
/* Optional string of the rendered version of the diagnostic as displayed
by rustc. Note that this may be influenced by the `--json` flag.
*/
"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"
"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"
}
```

Expand Down
12 changes: 12 additions & 0 deletions src/doc/rustdoc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,15 @@ the same CSS rules as the official `light` theme.
`--check-theme` is a separate mode in `rustdoc`. When `rustdoc` sees the
`--check-theme` flag, it discards all other flags and only performs the CSS rule
comparison operation.

### `--crate-version`: control the crate version

Using this flag looks like this:

```bash
$ rustdoc src/lib.rs --crate-version 1.3.37
```

When `rustdoc` receives this flag, it will print an extra "Version (version)" into the sidebar of
the crate root's docs. You can use this flag to differentiate between different versions of your
library's documentation.
12 changes: 0 additions & 12 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,6 @@ Markdown file, the URL given to `--markdown-playground-url` will take precedence
`--playground-url` and `#![doc(html_playground_url = "url")]` are present when rendering crate docs,
the attribute will take precedence.

### `--crate-version`: control the crate version

Using this flag looks like this:

```bash
$ rustdoc src/lib.rs -Z unstable-options --crate-version 1.3.37
```

When `rustdoc` receives this flag, it will print an extra "Version (version)" into the sidebar of
the crate root's docs. You can use this flag to differentiate between different versions of your
library's documentation.

### `--sort-modules-by-appearance`: control how items on module pages are sorted

Using this flag looks like this:
Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ pub mod str;
pub mod string;
#[cfg(target_has_atomic = "ptr")]
pub mod sync;
#[cfg(target_has_atomic = "ptr")]
pub mod task;
#[cfg(test)]
mod tests;
pub mod vec;
Expand Down
87 changes: 87 additions & 0 deletions src/liballoc/task.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#![unstable(feature = "wake_trait", issue = "69912")]
//! Types and Traits for working with asynchronous tasks.
use core::mem::{self, ManuallyDrop};
use core::task::{RawWaker, RawWakerVTable, Waker};

use crate::sync::Arc;

/// The implementation of waking a task on an executor.
///
/// This trait can be used to create a [`Waker`]. An executor can define an
/// implementation of this trait, and use that to construct a Waker to pass
/// to the tasks that are executed on that executor.
///
/// This trait is a memory-safe and ergonomic alternative to constructing a
/// [`RawWaker`]. It supports the common executor design in which the data
/// used to wake up a task is stored in an [`Arc`]. Some executors (especially
/// those for embedded systems) cannot use this API, which is why [`RawWaker`]
/// exists as an alternative for those systems.
#[unstable(feature = "wake_trait", issue = "69912")]
pub trait Wake {
/// Wake this task.
#[unstable(feature = "wake_trait", issue = "69912")]
fn wake(self: Arc<Self>);

/// Wake this task without consuming the waker.
///
/// If an executor supports a cheaper way to wake without consuming the
/// waker, it should override this method. By default, it clones the
/// [`Arc`] and calls `wake` on the clone.
#[unstable(feature = "wake_trait", issue = "69912")]
fn wake_by_ref(self: &Arc<Self>) {
self.clone().wake();
}
}

#[unstable(feature = "wake_trait", issue = "69912")]
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
fn from(waker: Arc<W>) -> Waker {
// SAFETY: This is safe because raw_waker safely constructs
// a RawWaker from Arc<W>.
unsafe { Waker::from_raw(raw_waker(waker)) }
}
}

#[unstable(feature = "wake_trait", issue = "69912")]
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
fn from(waker: Arc<W>) -> RawWaker {
raw_waker(waker)
}
}

// NB: This private function for constructing a RawWaker is used, rather than
// inlining this into the `From<Arc<W>> for RawWaker` impl, to ensure that
// the safety of `From<Arc<W>> for Waker` does not depend on the correct
// trait dispatch - instead both impls call this function directly and
// explicitly.
#[inline(always)]
fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
// Increment the reference count of the arc to clone it.
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
let waker: Arc<W> = Arc::from_raw(waker as *const W);
mem::forget(Arc::clone(&waker));
raw_waker(waker)
}

// Wake by value, moving the Arc into the Wake::wake function
unsafe fn wake<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: Arc<W> = Arc::from_raw(waker as *const W);
<W as Wake>::wake(waker);
}

// Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it
unsafe fn wake_by_ref<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: ManuallyDrop<Arc<W>> = ManuallyDrop::new(Arc::from_raw(waker as *const W));
<W as Wake>::wake_by_ref(&waker);
}

// Decrement the reference count of the Arc on drop
unsafe fn drop_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) {
mem::drop(Arc::from_raw(waker as *const W));
}

RawWaker::new(
Arc::into_raw(waker) as *const (),
&RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
)
}
4 changes: 2 additions & 2 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ impl<'a> ArgumentV1<'a> {
// SAFETY: `mem::transmute(x)` is safe because
// 1. `&'b T` keeps the lifetime it originated with `'b`
// (so as to not have an unbounded lifetime)
// 2. `&'b T` and `&'b Void` have the same memory layout
// 2. `&'b T` and `&'b Opaque` have the same memory layout
// (when `T` is `Sized`, as it is here)
// `mem::transmute(f)` is safe since `fn(&T, &mut Formatter<'_>) -> Result`
// and `fn(&Void, &mut Formatter<'_>) -> Result` have the same ABI
// and `fn(&Opaque, &mut Formatter<'_>) -> Result` have the same ABI
// (as long as `T` is `Sized`)
unsafe { ArgumentV1 { formatter: mem::transmute(f), value: mem::transmute(x) } }
}
Expand Down
15 changes: 2 additions & 13 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,8 @@ impl<'tcx> DepNodeParams<'tcx> for HirId {
/// some independent path or string that persists between runs without
/// the need to be mapped or unmapped. (This ensures we can serialize
/// them even in the absence of a tcx.)
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
RustcEncodable,
RustcDecodable,
HashStable
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable)]
pub struct WorkProductId {
hash: Fingerprint,
}
Expand Down
14 changes: 2 additions & 12 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,8 @@ impl CrateSource {
}
}

#[derive(
RustcEncodable,
RustcDecodable,
Copy,
Clone,
Ord,
PartialOrd,
Eq,
PartialEq,
Debug,
HashStable
)]
#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
#[derive(HashStable)]
pub enum DepKind {
/// A dependency that is only used for its macros.
MacrosOnly,
Expand Down
29 changes: 4 additions & 25 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,8 @@ use std::fmt;
// placate the same deriving in `ty::FreeRegion`, but we may want to
// actually attach a more meaningful ordering to scopes than the one
// generated via deriving here.
#[derive(
Clone,
PartialEq,
PartialOrd,
Eq,
Ord,
Hash,
Copy,
RustcEncodable,
RustcDecodable,
HashStable
)]
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, RustcEncodable, RustcDecodable)]
#[derive(HashStable)]
pub struct Scope {
pub id: hir::ItemLocalId,
pub data: ScopeData,
Expand All @@ -114,19 +104,8 @@ impl fmt::Debug for Scope {
}
}

#[derive(
Clone,
PartialEq,
PartialOrd,
Eq,
Ord,
Hash,
Debug,
Copy,
RustcEncodable,
RustcDecodable,
HashStable
)]
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)]
#[derive(HashStable)]
pub enum ScopeData {
Node,

Expand Down
28 changes: 4 additions & 24 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,8 @@ use std::ops::{Deref, DerefMut, Range};

// NOTE: When adding new fields, make sure to adjust the `Snapshot` impl in
// `src/librustc_mir/interpret/snapshot.rs`.
#[derive(
Clone,
Debug,
Eq,
PartialEq,
PartialOrd,
Ord,
Hash,
RustcEncodable,
RustcDecodable,
HashStable
)]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable)]
pub struct Allocation<Tag = (), Extra = ()> {
/// The actual bytes of the allocation.
/// Note that the bytes of a pointer represent the offset of the pointer.
Expand Down Expand Up @@ -759,18 +749,8 @@ type Block = u64;

/// A bitmask where each bit refers to the byte with the same index. If the bit is `true`, the byte
/// is defined. If it is `false` the byte is undefined.
#[derive(
Clone,
Debug,
Eq,
PartialEq,
PartialOrd,
Ord,
Hash,
RustcEncodable,
RustcDecodable,
HashStable
)]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable)]
pub struct UndefMask {
blocks: Vec<Block>,
len: Size,
Expand Down
11 changes: 8 additions & 3 deletions src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ macro_rules! err_exhaust {
};
}

#[macro_export]
macro_rules! err_machine_stop {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::MachineStop(Box::new($($tt)*))
};
}

// In the `throw_*` macros, avoid `return` to make them work with `try {}`.
#[macro_export]
macro_rules! throw_unsup {
Expand Down Expand Up @@ -79,9 +86,7 @@ macro_rules! throw_exhaust {

#[macro_export]
macro_rules! throw_machine_stop {
($($tt:tt)*) => {
Err::<!, _>($crate::mir::interpret::InterpError::MachineStop(Box::new($($tt)*)))?
};
($($tt:tt)*) => { Err::<!, _>(err_machine_stop!($($tt)*))? };
}

mod allocation;
Expand Down
14 changes: 2 additions & 12 deletions src/librustc/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,8 @@ impl<T: layout::HasDataLayout> PointerArithmetic for T {}
///
/// `Pointer` is also generic over the `Tag` associated with each pointer,
/// which is used to do provenance tracking during execution.
#[derive(
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
RustcEncodable,
RustcDecodable,
Hash,
HashStable
)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
#[derive(HashStable)]
pub struct Pointer<Tag = (), Id = AllocId> {
pub alloc_id: Id,
pub offset: Size,
Expand Down
Loading

0 comments on commit 1edd389

Please sign in to comment.