diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs index 04345867bf5c1..ba644e6111827 100644 --- a/src/bootstrap/bin/rustdoc.rs +++ b/src/bootstrap/bin/rustdoc.rs @@ -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. diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index b0d9a5b94641c..04da3cc1015b8 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -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") @@ -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. @@ -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") diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index ddbe26389fdc8..31e002810ce4b 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -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. diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index f704fe8e099b8..84e1ebe5e01f5 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -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: diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index d877ac6ac5c79..d55a1a3b63584 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -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; diff --git a/src/liballoc/task.rs b/src/liballoc/task.rs new file mode 100644 index 0000000000000..981095302c730 --- /dev/null +++ b/src/liballoc/task.rs @@ -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); + + /// 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.clone().wake(); + } +} + +#[unstable(feature = "wake_trait", issue = "69912")] +impl From> for Waker { + fn from(waker: Arc) -> Waker { + // SAFETY: This is safe because raw_waker safely constructs + // a RawWaker from Arc. + unsafe { Waker::from_raw(raw_waker(waker)) } + } +} + +#[unstable(feature = "wake_trait", issue = "69912")] +impl From> for RawWaker { + fn from(waker: Arc) -> RawWaker { + raw_waker(waker) + } +} + +// NB: This private function for constructing a RawWaker is used, rather than +// inlining this into the `From> for RawWaker` impl, to ensure that +// the safety of `From> for Waker` does not depend on the correct +// trait dispatch - instead both impls call this function directly and +// explicitly. +#[inline(always)] +fn raw_waker(waker: Arc) -> RawWaker { + // Increment the reference count of the arc to clone it. + unsafe fn clone_waker(waker: *const ()) -> RawWaker { + let waker: Arc = 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(waker: *const ()) { + let waker: Arc = Arc::from_raw(waker as *const W); + ::wake(waker); + } + + // Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it + unsafe fn wake_by_ref(waker: *const ()) { + let waker: ManuallyDrop> = ManuallyDrop::new(Arc::from_raw(waker as *const W)); + ::wake_by_ref(&waker); + } + + // Decrement the reference count of the Arc on drop + unsafe fn drop_waker(waker: *const ()) { + mem::drop(Arc::from_raw(waker as *const W)); + } + + RawWaker::new( + Arc::into_raw(waker) as *const (), + &RawWakerVTable::new(clone_waker::, wake::, wake_by_ref::, drop_waker::), + ) +} diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index a93b34fc46cb9..fe728d42c76f7 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -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) } } } diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index b32fa2cda8012..7cde57e1f13f6 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -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, } diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 9f5a56903aa6e..3a9d3c56dcead 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -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, diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 1a63dc9dcf977..73251ee2680df 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -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, @@ -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, diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index dd2a3f6c29a76..946b6add40a7e 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -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 { /// The actual bytes of the allocation. /// Note that the bytes of a pointer represent the offset of the pointer. @@ -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, len: Size, diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index dfe5adb1bbff0..a2f7a2d847e9f 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -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 { @@ -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; diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index 2cbe25f967426..7d862d43bba6b 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -111,18 +111,8 @@ impl 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 { pub alloc_id: Id, pub offset: Size, diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 04fe70b36c1e0..59e6b1b0c3788 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -23,19 +23,8 @@ pub struct RawConst<'tcx> { /// Represents a constant value in Rust. `Scalar` and `Slice` are optimizations for /// array length computations, enum discriminants and the pattern matching logic. -#[derive( - Copy, - Clone, - Debug, - Eq, - PartialEq, - PartialOrd, - Ord, - RustcEncodable, - RustcDecodable, - Hash, - HashStable -)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)] +#[derive(HashStable)] pub enum ConstValue<'tcx> { /// Used only for types with `layout::abi::Scalar` ABI and ZSTs. /// @@ -98,18 +87,8 @@ impl<'tcx> ConstValue<'tcx> { /// `memory::Allocation`. It is in many ways like a small chunk of a `Allocation`, up to 8 bytes in /// size. Like a range of bytes in an `Allocation`, a `Scalar` can either represent the raw bytes /// of a simple value or a pointer into another `Allocation` -#[derive( - Clone, - Copy, - Eq, - PartialEq, - Ord, - PartialOrd, - RustcEncodable, - RustcDecodable, - Hash, - HashStable -)] +#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)] +#[derive(HashStable)] pub enum Scalar { /// The raw bytes of a simple value. Raw { diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 9018cd2656f9f..5b1b6bb08bf5a 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -69,18 +69,8 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> { /// The various "big phases" that MIR goes through. /// /// Warning: ordering of variants is significant. -#[derive( - Copy, - Clone, - RustcEncodable, - RustcDecodable, - HashStable, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord -)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(HashStable)] pub enum MirPhase { Build = 0, Const = 1, @@ -439,18 +429,8 @@ pub struct SourceInfo { /////////////////////////////////////////////////////////////////////////// // Borrow kinds -#[derive( - Copy, - Clone, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - RustcEncodable, - RustcDecodable, - HashStable -)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable)] +#[derive(HashStable)] pub enum BorrowKind { /// Data must be immutable and is aliasable. Shared, diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index e7316ea763e8a..78b0ee271fb74 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2642,19 +2642,8 @@ impl<'tcx> FieldDef { /// /// You can get the environment type of a closure using /// `tcx.closure_env_ty()`. -#[derive( - Clone, - Copy, - PartialOrd, - Ord, - PartialEq, - Eq, - Hash, - Debug, - RustcEncodable, - RustcDecodable, - HashStable -)] +#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable)] pub enum ClosureKind { // Warning: Ordering is significant here! The ordering is chosen // because the trait Fn is a subtrait of FnMut and so in turn, and diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 096f63fdf2e68..0c14580717f92 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -31,38 +31,15 @@ use std::cmp::Ordering; use std::marker::PhantomData; use std::ops::Range; -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Debug, - RustcEncodable, - RustcDecodable, - HashStable, - TypeFoldable, - Lift -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable, TypeFoldable, Lift)] pub struct TypeAndMut<'tcx> { pub ty: Ty<'tcx>, pub mutbl: hir::Mutability, } -#[derive( - Clone, - PartialEq, - PartialOrd, - Eq, - Ord, - Hash, - RustcEncodable, - RustcDecodable, - Copy, - HashStable -)] +#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable, RustcDecodable, Copy)] +#[derive(HashStable)] /// A "free" region `fr` can be interpreted as "some region /// at least as big as the scope `fr.scope`". pub struct FreeRegion { @@ -70,18 +47,8 @@ pub struct FreeRegion { pub bound_region: BoundRegion, } -#[derive( - Clone, - PartialEq, - PartialOrd, - Eq, - Ord, - Hash, - RustcEncodable, - RustcDecodable, - Copy, - HashStable -)] +#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable, RustcDecodable, Copy)] +#[derive(HashStable)] pub enum BoundRegion { /// An anonymous region parameter for a given fn (&T) BrAnon(u32), @@ -119,18 +86,8 @@ impl BoundRegion { /// N.B., if you change this, you'll probably want to change the corresponding /// AST structure in `librustc_ast/ast.rs` as well. -#[derive( - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - RustcEncodable, - RustcDecodable, - HashStable, - Debug -)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(HashStable)] #[rustc_diagnostic_item = "TyKind"] pub enum TyKind<'tcx> { /// The primitive boolean type. Written as `bool`. @@ -1147,18 +1104,8 @@ impl<'tcx> PolyFnSig<'tcx> { pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder>>; -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - RustcEncodable, - RustcDecodable, - HashStable -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(HashStable)] pub struct ParamTy { pub index: u32, pub name: Symbol, @@ -1182,18 +1129,8 @@ impl<'tcx> ParamTy { } } -#[derive( - Copy, - Clone, - Hash, - RustcEncodable, - RustcDecodable, - Eq, - PartialEq, - Ord, - PartialOrd, - HashStable -)] +#[derive(Copy, Clone, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)] +#[derive(HashStable)] pub struct ParamConst { pub index: u32, pub name: Symbol, @@ -1465,18 +1402,8 @@ impl Atom for RegionVid { } } -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - RustcEncodable, - RustcDecodable, - HashStable -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(HashStable)] pub enum InferTy { TyVar(TyVid), IntVar(IntVid), @@ -1494,37 +1421,15 @@ rustc_index::newtype_index! { pub struct BoundVar { .. } } -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Debug, - RustcEncodable, - RustcDecodable, - HashStable -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable)] pub struct BoundTy { pub var: BoundVar, pub kind: BoundTyKind, } -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Debug, - RustcEncodable, - RustcDecodable, - HashStable -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable)] pub enum BoundTyKind { Anon, Param(Symbol), @@ -2358,19 +2263,8 @@ impl<'tcx> TyS<'tcx> { } /// Typed constant value. -#[derive( - Copy, - Clone, - Debug, - Hash, - RustcEncodable, - RustcDecodable, - Eq, - PartialEq, - Ord, - PartialOrd, - HashStable -)] +#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)] +#[derive(HashStable)] pub struct Const<'tcx> { pub ty: Ty<'tcx>, @@ -2499,19 +2393,8 @@ impl<'tcx> Const<'tcx> { impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx Const<'tcx> {} /// Represents a constant in Rust. -#[derive( - Copy, - Clone, - Debug, - Eq, - PartialEq, - PartialOrd, - Ord, - RustcEncodable, - RustcDecodable, - Hash, - HashStable -)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)] +#[derive(HashStable)] pub enum ConstKind<'tcx> { /// A const generic parameter. Param(ParamConst), @@ -2549,19 +2432,8 @@ impl<'tcx> ConstKind<'tcx> { } /// An inference variable for a const, for use in const generics. -#[derive( - Copy, - Clone, - Debug, - Eq, - PartialEq, - PartialOrd, - Ord, - RustcEncodable, - RustcDecodable, - Hash, - HashStable -)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)] +#[derive(HashStable)] pub enum InferConst<'tcx> { /// Infer the value of the const. Var(ConstVid<'tcx>), diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 1f512f1dde7d6..8ace84b7832e6 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -1047,10 +1047,7 @@ pub fn needs_drop_components( // Foreign types can never have destructors. ty::Foreign(..) => Ok(SmallVec::new()), - // Pessimistically assume that all generators will require destructors - // as we don't know if a destructor is a noop or not until after the MIR - // state transformation pass. - ty::Generator(..) | ty::Dynamic(..) | ty::Error => Err(AlwaysRequiresDrop), + ty::Dynamic(..) | ty::Error => Err(AlwaysRequiresDrop), ty::Slice(ty) => needs_drop_components(ty, target_layout), ty::Array(elem_ty, size) => { @@ -1083,7 +1080,8 @@ pub fn needs_drop_components( | ty::Placeholder(..) | ty::Opaque(..) | ty::Infer(_) - | ty::Closure(..) => Ok(smallvec![ty]), + | ty::Closure(..) + | ty::Generator(..) => Ok(smallvec![ty]), } } diff --git a/src/librustc_ast/ast.rs b/src/librustc_ast/ast.rs index 9d00cbe1951ea..c796a37553164 100644 --- a/src/librustc_ast/ast.rs +++ b/src/librustc_ast/ast.rs @@ -684,19 +684,8 @@ pub enum PatKind { MacCall(MacCall), } -#[derive( - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - RustcEncodable, - RustcDecodable, - Debug, - Copy, - HashStable_Generic -)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(HashStable_Generic)] pub enum Mutability { Mut, Not, @@ -1321,19 +1310,8 @@ pub enum CaptureBy { /// The movability of a generator / closure literal: /// whether a generator contains self-references, causing it to be `!Unpin`. -#[derive( - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - RustcEncodable, - RustcDecodable, - Debug, - Copy, - HashStable_Generic -)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(HashStable_Generic)] pub enum Movability { /// May contain self-references, `!Unpin`. Static, @@ -1614,19 +1592,8 @@ pub struct FnSig { pub decl: P, } -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - HashStable_Generic, - RustcEncodable, - RustcDecodable, - Debug -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(HashStable_Generic)] pub enum FloatTy { F32, F64, @@ -1655,19 +1622,8 @@ impl FloatTy { } } -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - HashStable_Generic, - RustcEncodable, - RustcDecodable, - Debug -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(HashStable_Generic)] pub enum IntTy { Isize, I8, @@ -1731,19 +1687,8 @@ impl IntTy { } } -#[derive( - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - HashStable_Generic, - RustcEncodable, - RustcDecodable, - Copy, - Debug -)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Copy, Debug)] +#[derive(HashStable_Generic)] pub enum UintTy { Usize, U8, diff --git a/src/librustc_attr/builtin.rs b/src/librustc_attr/builtin.rs index 99083cca6cb34..a16b79993912d 100644 --- a/src/librustc_attr/builtin.rs +++ b/src/librustc_attr/builtin.rs @@ -120,17 +120,8 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op } /// Represents the #[stable], #[unstable], #[rustc_deprecated] attributes. -#[derive( - RustcEncodable, - RustcDecodable, - Copy, - Clone, - Debug, - PartialEq, - Eq, - Hash, - HashStable_Generic -)] +#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(HashStable_Generic)] pub struct Stability { pub level: StabilityLevel, pub feature: Symbol, @@ -138,17 +129,8 @@ pub struct Stability { } /// Represents the #[rustc_const_unstable] and #[rustc_const_stable] attributes. -#[derive( - RustcEncodable, - RustcDecodable, - Copy, - Clone, - Debug, - PartialEq, - Eq, - Hash, - HashStable_Generic -)] +#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(HashStable_Generic)] pub struct ConstStability { pub level: StabilityLevel, pub feature: Symbol, @@ -159,18 +141,8 @@ pub struct ConstStability { } /// The available stability levels. -#[derive( - RustcEncodable, - RustcDecodable, - PartialEq, - PartialOrd, - Copy, - Clone, - Debug, - Eq, - Hash, - HashStable_Generic -)] +#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)] +#[derive(HashStable_Generic)] pub enum StabilityLevel { // Reason for the current stability level and the relevant rust-lang issue Unstable { reason: Option, issue: Option, is_soft: bool }, @@ -186,18 +158,8 @@ impl StabilityLevel { } } -#[derive( - RustcEncodable, - RustcDecodable, - PartialEq, - PartialOrd, - Copy, - Clone, - Debug, - Eq, - Hash, - HashStable_Generic -)] +#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)] +#[derive(HashStable_Generic)] pub struct RustcDeprecation { pub since: Symbol, pub reason: Symbol, diff --git a/src/librustc_mir/const_eval/error.rs b/src/librustc_mir/const_eval/error.rs index 63ad9ec8cae9e..dc23eba643e3e 100644 --- a/src/librustc_mir/const_eval/error.rs +++ b/src/librustc_mir/const_eval/error.rs @@ -5,7 +5,7 @@ use rustc::mir::AssertKind; use rustc_span::Symbol; use super::InterpCx; -use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine}; +use crate::interpret::{ConstEvalErr, InterpErrorInfo, Machine}; /// The CTFE machine has some custom error kinds. #[derive(Clone, Debug)] @@ -21,7 +21,7 @@ pub enum ConstEvalErrKind { // handle these. impl<'tcx> Into> for ConstEvalErrKind { fn into(self) -> InterpErrorInfo<'tcx> { - InterpError::MachineStop(Box::new(self.to_string())).into() + err_machine_stop!(self.to_string()).into() } } diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index f8dfddef2bbd5..4c380d1141806 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -561,7 +561,7 @@ fn write_mir_sig( ty::print::with_forced_impl_filename_line(|| { // see notes on #41697 elsewhere - write!(w, " {}", tcx.def_path_str(src.def_id())) + write!(w, "{}", tcx.def_path_str(src.def_id())) })?; if src.promoted.is_none() && is_function { diff --git a/src/librustc_span/def_id.rs b/src/librustc_span/def_id.rs index 29561c91f3318..3551220c5c54a 100644 --- a/src/librustc_span/def_id.rs +++ b/src/librustc_span/def_id.rs @@ -105,19 +105,8 @@ impl ::std::fmt::Debug for CrateNum { } } -#[derive( - Copy, - Clone, - Hash, - PartialEq, - Eq, - PartialOrd, - Ord, - Debug, - RustcEncodable, - RustcDecodable, - HashStable_Generic -)] +#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable_Generic)] pub struct DefPathHash(pub Fingerprint); impl Borrow for DefPathHash { diff --git a/src/librustc_span/edition.rs b/src/librustc_span/edition.rs index 3017191563b0a..b1ac7f04321eb 100644 --- a/src/librustc_span/edition.rs +++ b/src/librustc_span/edition.rs @@ -5,18 +5,8 @@ use std::str::FromStr; use rustc_macros::HashStable_Generic; /// The edition of the compiler (RFC 2052) -#[derive( - Clone, - Copy, - Hash, - PartialEq, - PartialOrd, - Debug, - RustcEncodable, - RustcDecodable, - Eq, - HashStable_Generic -)] +#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable, Eq)] +#[derive(HashStable_Generic)] pub enum Edition { // editions must be kept in order, oldest to newest /// The 2015 edition diff --git a/src/librustc_span/hygiene.rs b/src/librustc_span/hygiene.rs index e073d735a1225..0afa2333e0615 100644 --- a/src/librustc_span/hygiene.rs +++ b/src/librustc_span/hygiene.rs @@ -59,18 +59,8 @@ pub struct ExpnId(u32); /// A property of a macro expansion that determines how identifiers /// produced by that expansion are resolved. -#[derive( - Copy, - Clone, - PartialEq, - Eq, - PartialOrd, - Hash, - Debug, - RustcEncodable, - RustcDecodable, - HashStable_Generic -)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable_Generic)] pub enum Transparency { /// Identifier produced by a transparent expansion is always resolved at call-site. /// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this. @@ -747,17 +737,8 @@ impl ExpnKind { } /// The kind of macro invocation or definition. -#[derive( - Clone, - Copy, - PartialEq, - Eq, - RustcEncodable, - RustcDecodable, - Hash, - Debug, - HashStable_Generic -)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum MacroKind { /// A bang macro `foo!()`. Bang, diff --git a/src/librustc_span/lib.rs b/src/librustc_span/lib.rs index 28864737072b2..3ebcef947bc37 100644 --- a/src/librustc_span/lib.rs +++ b/src/librustc_span/lib.rs @@ -72,18 +72,8 @@ impl Globals { scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals); /// Differentiates between real files and common virtual files. -#[derive( - Debug, - Eq, - PartialEq, - Clone, - Ord, - PartialOrd, - Hash, - RustcDecodable, - RustcEncodable, - HashStable_Generic -)] +#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)] +#[derive(HashStable_Generic)] pub enum FileName { Real(PathBuf), /// Call to `quote!`. diff --git a/src/librustc_target/spec/abi.rs b/src/librustc_target/spec/abi.rs index ac4c561402b67..1736063cc5f7c 100644 --- a/src/librustc_target/spec/abi.rs +++ b/src/librustc_target/spec/abi.rs @@ -5,19 +5,8 @@ use rustc_macros::HashStable_Generic; #[cfg(test)] mod tests; -#[derive( - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - RustcEncodable, - RustcDecodable, - Clone, - Copy, - Debug, - HashStable_Generic -)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)] +#[derive(HashStable_Generic)] pub enum Abi { // N.B., this ordering MUST match the AbiDatas array below. // (This is ensured by the test indices_are_correct().) diff --git a/src/librustc_ty/needs_drop.rs b/src/librustc_ty/needs_drop.rs index 37af8168f87d9..cbbb2aa19fd83 100644 --- a/src/librustc_ty/needs_drop.rs +++ b/src/librustc_ty/needs_drop.rs @@ -99,6 +99,23 @@ where } } + ty::Generator(def_id, substs, _) => { + let substs = substs.as_generator(); + for upvar_ty in substs.upvar_tys(def_id, tcx) { + queue_type(self, upvar_ty); + } + + let witness = substs.witness(def_id, tcx); + let interior_tys = match &witness.kind { + ty::GeneratorWitness(tys) => tcx.erase_late_bound_regions(tys), + _ => bug!(), + }; + + for interior_ty in interior_tys { + queue_type(self, interior_ty); + } + } + // Check for a `Drop` impl and whether this is a union or // `ManuallyDrop`. If it's a struct or enum without a `Drop` // impl then check whether the field types need `Drop`. diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 3c1f0509bba4d..33cabad9193c4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -267,7 +267,7 @@ fn opts() -> Vec { unstable("display-warnings", |o| { o.optflag("", "display-warnings", "to print code warnings when testing doc") }), - unstable("crate-version", |o| { + stable("crate-version", |o| { o.optopt("", "crate-version", "crate version to print into documentation", "VERSION") }), unstable("sort-modules-by-appearance", |o| { diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 1f122b02b6a29..e5dad307a209a 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -310,6 +310,7 @@ #![feature(untagged_unions)] #![feature(unwind_attributes)] #![feature(vec_into_raw_parts)] +#![feature(wake_trait)] // NB: the above list is sorted to minimize merge conflicts. #![default_lib_allocator] @@ -463,9 +464,14 @@ pub mod time; #[stable(feature = "futures_api", since = "1.36.0")] pub mod task { //! Types and Traits for working with asynchronous tasks. + #[doc(inline)] #[stable(feature = "futures_api", since = "1.36.0")] pub use core::task::*; + + #[doc(inline)] + #[unstable(feature = "wake_trait", issue = "69912")] + pub use alloc::task::*; } #[stable(feature = "futures_api", since = "1.36.0")] diff --git a/src/test/mir-opt/generator-drop-cleanup.rs b/src/test/mir-opt/generator-drop-cleanup.rs index 278dc49c92605..c4742e8156938 100644 --- a/src/test/mir-opt/generator-drop-cleanup.rs +++ b/src/test/mir-opt/generator-drop-cleanup.rs @@ -5,6 +5,7 @@ fn main() { let gen = || { + let _s = String::new(); yield; }; } @@ -13,35 +14,49 @@ fn main() { // START rustc.main-{{closure}}.generator_drop.0.mir // bb0: { -// _7 = discriminant((*_1)); -// switchInt(move _7) -> [0u32: bb4, 3u32: bb7, otherwise: bb8]; +// _9 = discriminant((*_1)); +// switchInt(move _9) -> [0u32: bb7, 3u32: bb11, otherwise: bb12]; // } -// bb1: { -// StorageDead(_4); -// StorageDead(_3); -// goto -> bb5; +// bb1 (cleanup): { +// resume; // } -// bb2: { -// return; +// bb2 (cleanup): { +// nop; +// goto -> bb8; // } // bb3: { -// return; +// StorageDead(_5); +// StorageDead(_4); +// drop((((*_1) as variant#3).0: std::string::String)) -> [return: bb4, unwind: bb2]; // } // bb4: { -// goto -> bb6; +// nop; +// goto -> bb9; // } // bb5: { -// goto -> bb2; +// return; // } // bb6: { -// goto -> bb3; +// return; // } // bb7: { -// StorageLive(_3); -// StorageLive(_4); +// goto -> bb10; +// } +// bb8 (cleanup): { // goto -> bb1; // } -// bb8: { +// bb9: { +// goto -> bb5; +// } +// bb10: { +// goto -> bb6; +// } +// bb11: { +// StorageLive(_4); +// StorageLive(_5); +// goto -> bb3; +// } +// bb12: { // return; // } // END rustc.main-{{closure}}.generator_drop.0.mir diff --git a/src/test/mir-opt/retag.rs b/src/test/mir-opt/retag.rs index e917441200b8a..a0a7a760c2da5 100644 --- a/src/test/mir-opt/retag.rs +++ b/src/test/mir-opt/retag.rs @@ -121,7 +121,7 @@ fn main() { // } // END rustc.main-{{closure}}.SimplifyCfg-elaborate-drops.after.mir // START rustc.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir -// fn std::intrinsics::drop_in_place(_1: *mut Test) -> () { +// fn std::intrinsics::drop_in_place(_1: *mut Test) -> () { // ... // bb0: { // Retag([raw] _1); diff --git a/src/test/rustdoc/crate-version.rs b/src/test/rustdoc/crate-version.rs index 9ea84ac031211..893af5c61332d 100644 --- a/src/test/rustdoc/crate-version.rs +++ b/src/test/rustdoc/crate-version.rs @@ -1,3 +1,3 @@ -// compile-flags: --crate-version=1.3.37 -Z unstable-options +// compile-flags: --crate-version=1.3.37 // @has 'crate_version/index.html' '//div[@class="block version"]/p' 'Version 1.3.37' diff --git a/src/test/ui/generator/borrowing.stderr b/src/test/ui/generator/borrowing.stderr index 83987e19839ce..38e1ace8c4efb 100644 --- a/src/test/ui/generator/borrowing.stderr +++ b/src/test/ui/generator/borrowing.stderr @@ -1,19 +1,16 @@ error[E0597]: `a` does not live long enough --> $DIR/borrowing.rs:9:33 | +LL | let _b = { + | -- borrow later stored here +LL | let a = 3; LL | Pin::new(&mut || yield &a).resume(()) - | ----------^ - | | | - | | borrowed value does not live long enough + | -- ^ borrowed value does not live long enough + | | | value captured here by generator - | a temporary with access to the borrow is created here ... LL | LL | }; - | -- ... and the borrow might be used here, when that temporary is dropped and runs the destructor for generator - | | - | `a` dropped here while still borrowed - | - = note: The temporary is part of an expression at the end of a block. Consider forcing this temporary to be dropped sooner, before the block's local variables are dropped. For example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block. + | - `a` dropped here while still borrowed error[E0597]: `a` does not live long enough --> $DIR/borrowing.rs:16:20 diff --git a/src/test/ui/generator/retain-resume-ref.stderr b/src/test/ui/generator/retain-resume-ref.stderr index bc715c7030eb3..e33310d12d9ef 100644 --- a/src/test/ui/generator/retain-resume-ref.stderr +++ b/src/test/ui/generator/retain-resume-ref.stderr @@ -4,10 +4,9 @@ error[E0499]: cannot borrow `thing` as mutable more than once at a time LL | gen.as_mut().resume(&mut thing); | ---------- first mutable borrow occurs here LL | gen.as_mut().resume(&mut thing); - | ^^^^^^^^^^ second mutable borrow occurs here -LL | -LL | } - | - first borrow might be used here, when `gen` is dropped and runs the destructor for generator + | ------ ^^^^^^^^^^ second mutable borrow occurs here + | | + | first borrow later used by call error: aborting due to previous error diff --git a/src/test/ui/issues/issue-53275.rs b/src/test/ui/issues/issue-53275.rs new file mode 100644 index 0000000000000..5ae6fb2d47249 --- /dev/null +++ b/src/test/ui/issues/issue-53275.rs @@ -0,0 +1,9 @@ +// build-pass + +#![crate_type = "lib"] +#![allow(unconditional_panic)] +struct S(u8); + +pub fn ice() { + S([][0]); +}