From 5ece5f9610652200f7805a238aabf28f5125d942 Mon Sep 17 00:00:00 2001 From: ishitatsuyuki Date: Thu, 31 Jan 2019 18:28:22 +0900 Subject: [PATCH 01/35] Fix fallout from #57667 --- src/libsyntax/ptr.rs | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index bc43630ae59b3..9afcb7c4621c9 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -29,7 +29,7 @@ use std::fmt::{self, Display, Debug}; use std::iter::FromIterator; use std::ops::{Deref, DerefMut}; -use std::{mem, ptr, slice, vec}; +use std::{slice, vec}; use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -66,45 +66,18 @@ impl P { pub fn map(mut self, f: F) -> P where F: FnOnce(T) -> T, { - let p: *mut T = &mut *self.ptr; + let x = f(*self.ptr); + *self.ptr = x; - // Leak self in case of panic. - // FIXME(eddyb) Use some sort of "free guard" that - // only deallocates, without dropping the pointee, - // in case the call the `f` below ends in a panic. - mem::forget(self); - - unsafe { - ptr::write(p, f(ptr::read(p))); - - // Recreate self from the raw pointer. - P { ptr: Box::from_raw(p) } - } + self } /// Optionally produce a new `P` from `self` without reallocating. pub fn filter_map(mut self, f: F) -> Option> where F: FnOnce(T) -> Option, { - let p: *mut T = &mut *self.ptr; - - // Leak self in case of panic. - // FIXME(eddyb) Use some sort of "free guard" that - // only deallocates, without dropping the pointee, - // in case the call the `f` below ends in a panic. - mem::forget(self); - - unsafe { - if let Some(v) = f(ptr::read(p)) { - ptr::write(p, v); - - // Recreate self from the raw pointer. - Some(P { ptr: Box::from_raw(p) }) - } else { - drop(Box::from_raw(p)); - None - } - } + *self.ptr = f(*self.ptr)?; + Some(self) } } From e0eae56ec2307459c4bd2f95ef2713b24377a27d Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Mon, 1 Apr 2019 10:49:28 +0200 Subject: [PATCH 02/35] Updated RELEASES.md for 1.34.0 --- RELEASES.md | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index a49e072e9eaa7..7cd5847616c8d 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,153 @@ +Version v1.34.0 (2019-04-11) +========================== + +Language +-------- +- [You can now use `#[deprecation = "reason"]`][58166] as a shorthand for + `#[deprecation(note = "reason")]`. This was previously allowed as a syntax bug + but had no effect. +- [You can now accept token streams in `#[attr()]`,`#[attr[]]`, and + `#[attr{}]` procedural macros.][57367] +- [You can now write `extern crate self as foo;`][57407] to import the your + crate's root into the extern prelude. + + +Compiler +-------- +- [You can now target `riscv64imac-unknown-none-elf` and + `riscv64gc-unknown-none-elf`.][58406] +- [You can now enable linker plugin LTO optimisations with + `-C linker-plugin-lto`.][58057] This allows rustc to compile your Rust code + into LLVM bitcode allowing LLVM to perform LTO optimisations across C/C++ FFI + boundaries. +- [You can now target `powerpc64-unknown-freebsd`.][57809] + + +Libraries +--------- +- [The trait bounds have been removed on some of `HashMap`'s and + `HashSet`'s basic methods.][58370] Most notably you no longer require + the `Hash` trait to create an iterator. +- [Relax Ord trait bounds have been removed on some of `BinaryHeap`'s basic + methods.][58421] Most notably you no longer require the `Ord` trait to create + an iterator. +- [The methods `overflowing_neg` and `wrapping_neg` are now `const` functions + for all numeric types.][58044] +- [Indexing a `str` is now generic over all types that + implement `SliceIndex`.][57604] +- [`str::trim`, `str::trim_matches`, `str::trim_{start, end}`, and + `str::trim_{start, end}_matches` are now `#[must_use]`][57106] and will + produce a warning if their returning type is unused. +- [The methods `checked_pow`, `saturating_pow`, `wrapping_pow`, and + `overflowing_pow` are now available for all numeric types.][57873] These are + equivalvent to methods such as `wrapping_add` for the `pow` operation. + + +Stabilized APIs +--------------- + +#### std & core +* [`Any::type_id`] +* [`Error::type_id`] +* [`atomic::AtomicI16`] +* [`atomic::AtomicI32`] +* [`atomic::AtomicI64`] +* [`atomic::AtomicI8`] +* [`atomic::AtomicU16`] +* [`atomic::AtomicU32`] +* [`atomic::AtomicU64`] +* [`atomic::AtomicU8`] +* [`convert::Infallible`] +* [`convert::TryFrom`] +* [`convert::TryInto`] +* [`iter::FromFn`] +* [`iter::Successors`] +* [`iter::from_fn`] +* [`iter::successors`] +* [`num::NonZeroI128`] +* [`num::NonZeroI16`] +* [`num::NonZeroI32`] +* [`num::NonZeroI64`] +* [`num::NonZeroI8`] +* [`num::NonZeroIsize`] +* [`slice::sort_by_cached_key`] +* [`str::escape_debug`] +* [`str::escape_default`] +* [`str::escape_unicode`] +* [`str::split_ascii_whitespace`] + +#### std +* [`Instant::checked_add`] +* [`Instant::checked_sub`] +* [`SystemTime::checked_add`] +* [`SystemTime::checked_sub`] + +Cargo +----- +- [You can now use alternatives registries to crates.io.][cargo/6654] + +Misc +---- +- [You can now use the `?` operator in your documentation tests without manually + adding `fn main() -> Result<(), _> {}`.][56470] + +Compatibility Notes +------------------- +- [`Command::before_exec` is now deprecated in favor of the + unsafe method `Command::pre_exec`.][58059] +- [Use of `ATOMIC_{BOOL, ISIZE, USIZE}_INIT` is now deprecated.][57425] As you + can now use `const` functions in `static` variables. + +[58370]: https://github.com/rust-lang/rust/pull/58370/ +[58406]: https://github.com/rust-lang/rust/pull/58406/ +[58421]: https://github.com/rust-lang/rust/pull/58421/ +[58166]: https://github.com/rust-lang/rust/pull/58166/ +[58044]: https://github.com/rust-lang/rust/pull/58044/ +[58057]: https://github.com/rust-lang/rust/pull/58057/ +[58059]: https://github.com/rust-lang/rust/pull/58059/ +[57809]: https://github.com/rust-lang/rust/pull/57809/ +[57873]: https://github.com/rust-lang/rust/pull/57873/ +[57604]: https://github.com/rust-lang/rust/pull/57604/ +[57367]: https://github.com/rust-lang/rust/pull/57367/ +[57407]: https://github.com/rust-lang/rust/pull/57407/ +[57425]: https://github.com/rust-lang/rust/pull/57425/ +[57106]: https://github.com/rust-lang/rust/pull/57106/ +[56470]: https://github.com/rust-lang/rust/pull/56470/ +[cargo/6654]: https://github.com/rust-lang/cargo/pull/6654/ +[`Any::type_id`]: https://doc.rust-lang.org/std/any/trait.Any.html#tymethod.type_id +[`Error::type_id`]: https://doc.rust-lang.org/std/error/trait.Error.html#tymethod.type_id +[`atomic::AtomicI16`]: https://doc.rust-lang.org/std/atomic/struct.AtomicI16.html +[`atomic::AtomicI32`]: https://doc.rust-lang.org/std/atomic/struct.AtomicI32.html +[`atomic::AtomicI64`]: https://doc.rust-lang.org/std/atomic/struct.AtomicI64.html +[`atomic::AtomicI8`]: https://doc.rust-lang.org/std/atomic/struct.AtomicI8.html +[`atomic::AtomicU16`]: https://doc.rust-lang.org/std/atomic/struct.AtomicU16.html +[`atomic::AtomicU32`]: https://doc.rust-lang.org/std/atomic/struct.AtomicU32.html +[`atomic::AtomicU64`]: https://doc.rust-lang.org/std/atomic/struct.AtomicU64.html +[`atomic::AtomicU8`]: https://doc.rust-lang.org/std/atomic/struct.AtomicU8.html +[`convert::Infallible`]: https://doc.rust-lang.org/std/convert/enum.Infallible.html +[`convert::TryFrom`]: https://doc.rust-lang.org/std/convert/trait.TryFrom.html +[`convert::TryInto`]: https://doc.rust-lang.org/std/convert/trait.TryInto.html +[`iter::FromFn`]: https://doc.rust-lang.org/std/iter/struct.FromFn.html +[`iter::Successors`]: https://doc.rust-lang.org/std/iter/struct.Successors.html +[`iter::from_fn`]: https://doc.rust-lang.org/std/iter/fn.from_fn.html +[`iter::successors`]: https://doc.rust-lang.org/std/iter/fn.successors.html +[`num::NonZeroI128`]: https://doc.rust-lang.org/std/num/struct.NonZeroI128.html +[`num::NonZeroI16`]: https://doc.rust-lang.org/std/num/struct.NonZeroI16.html +[`num::NonZeroI32`]: https://doc.rust-lang.org/std/num/struct.NonZeroI32.html +[`num::NonZeroI64`]: https://doc.rust-lang.org/std/num/struct.NonZeroI64.html +[`num::NonZeroI8`]: https://doc.rust-lang.org/std/num/struct.NonZeroI8.html +[`num::NonZeroIsize`]: https://doc.rust-lang.org/std/num/struct.NonZeroIsize.html +[`slice::sort_by_cached_key`]: https://doc.rust-lang.org/std/slice/fn.sort_by_cached_key +[`str::escape_debug`]: https://doc.rust-lang.org/std/primitive.str.html#method.escape_debug +[`str::escape_default`]: https://doc.rust-lang.org/std/primitive.str.html#method.escape_default +[`str::escape_unicode`]: https://doc.rust-lang.org/std/primitive.str.html#method.escape_unicode +[`str::split_ascii_whitespace`]: https://doc.rust-lang.org/std/primitive.str.html#method.split_ascii_whitespace +[`Instant::checked_add`]: https://doc.rust-lang.org/std/time/struct.Instant.html#method.checked_add +[`Instant::checked_sub`]: https://doc.rust-lang.org/std/time/struct.Instant.html#method.checked_sub +[`SystemTime::checked_add`]: https://doc.rust-lang.org/std/time/struct.SystemTime.html#method.checked_add +[`SystemTime::checked_sub`]: https://doc.rust-lang.org/std/time/struct.SystemTime.html#method.checked_sub + + Version 1.33.0 (2019-02-28) ========================== @@ -99,6 +249,8 @@ Stabilized APIs Cargo ----- +- [You can now publish crates which require a feature flag to compile with + `cargo publish --features` or `cargo publish --all-features`.][cargo/6453] - [Cargo should now rebuild a crate if a file was modified during the initial build.][cargo/6484] @@ -135,6 +287,7 @@ Compatibility Notes [57535]: https://github.com/rust-lang/rust/pull/57535/ [57566]: https://github.com/rust-lang/rust/pull/57566/ [57615]: https://github.com/rust-lang/rust/pull/57615/ +[cargo/6453]: https://github.com/rust-lang/cargo/pull/6453/ [cargo/6484]: https://github.com/rust-lang/cargo/pull/6484/ [`unix::FileExt::read_exact_at`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#method.read_exact_at [`unix::FileExt::write_all_at`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#method.write_all_at From a6391448969e01c36c5b1b7fe3f4bb408687062f Mon Sep 17 00:00:00 2001 From: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> Date: Tue, 2 Apr 2019 10:09:48 +0200 Subject: [PATCH 03/35] Update RELEASES.md --- RELEASES.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 7cd5847616c8d..3a005f1cc09dd 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,14 +1,14 @@ -Version v1.34.0 (2019-04-11) +Version 1.34.0 (2019-04-11) ========================== Language -------- -- [You can now use `#[deprecation = "reason"]`][58166] as a shorthand for - `#[deprecation(note = "reason")]`. This was previously allowed as a syntax bug +- [You can now use `#[deprecated = "reason"]`][58166] as a shorthand for + `#[deprecated(note = "reason")]`. This was previously allowed by mistake but had no effect. - [You can now accept token streams in `#[attr()]`,`#[attr[]]`, and `#[attr{}]` procedural macros.][57367] -- [You can now write `extern crate self as foo;`][57407] to import the your +- [You can now write `extern crate self as foo;`][57407] to import your crate's root into the extern prelude. @@ -28,7 +28,7 @@ Libraries - [The trait bounds have been removed on some of `HashMap`'s and `HashSet`'s basic methods.][58370] Most notably you no longer require the `Hash` trait to create an iterator. -- [Relax Ord trait bounds have been removed on some of `BinaryHeap`'s basic +- [The `Ord` trait bounds have been removed on some of `BinaryHeap`'s basic methods.][58421] Most notably you no longer require the `Ord` trait to create an iterator. - [The methods `overflowing_neg` and `wrapping_neg` are now `const` functions @@ -60,8 +60,6 @@ Stabilized APIs * [`convert::Infallible`] * [`convert::TryFrom`] * [`convert::TryInto`] -* [`iter::FromFn`] -* [`iter::Successors`] * [`iter::from_fn`] * [`iter::successors`] * [`num::NonZeroI128`] @@ -84,7 +82,7 @@ Stabilized APIs Cargo ----- -- [You can now use alternatives registries to crates.io.][cargo/6654] +- [You can now use alternative registries to crates.io.][cargo/6654] Misc ---- @@ -127,8 +125,6 @@ Compatibility Notes [`convert::Infallible`]: https://doc.rust-lang.org/std/convert/enum.Infallible.html [`convert::TryFrom`]: https://doc.rust-lang.org/std/convert/trait.TryFrom.html [`convert::TryInto`]: https://doc.rust-lang.org/std/convert/trait.TryInto.html -[`iter::FromFn`]: https://doc.rust-lang.org/std/iter/struct.FromFn.html -[`iter::Successors`]: https://doc.rust-lang.org/std/iter/struct.Successors.html [`iter::from_fn`]: https://doc.rust-lang.org/std/iter/fn.from_fn.html [`iter::successors`]: https://doc.rust-lang.org/std/iter/fn.successors.html [`num::NonZeroI128`]: https://doc.rust-lang.org/std/num/struct.NonZeroI128.html From f41f88abff03287a344af4cadc2ee083f714e5b9 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Fri, 5 Apr 2019 19:38:24 +0200 Subject: [PATCH 04/35] Update RELEASES.md Co-Authored-By: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 3a005f1cc09dd..821889d64a5fb 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -245,7 +245,7 @@ Stabilized APIs Cargo ----- -- [You can now publish crates which require a feature flag to compile with +- [You can now publish crates that require a feature flag to compile with `cargo publish --features` or `cargo publish --all-features`.][cargo/6453] - [Cargo should now rebuild a crate if a file was modified during the initial build.][cargo/6484] From c02a36acc170595c488ff96727515d8c56da7539 Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Sun, 31 Mar 2019 16:54:05 +0200 Subject: [PATCH 05/35] Remove #[doc(hidden)] from Error::type_id --- src/libstd/error.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 17e50a649fa52..aec85b660cae0 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -196,7 +196,6 @@ pub trait Error: Debug + Display { fn source(&self) -> Option<&(dyn Error + 'static)> { None } /// Gets the `TypeId` of `self` - #[doc(hidden)] #[stable(feature = "error_type_id", since = "1.34.0")] fn type_id(&self) -> TypeId where Self: 'static { TypeId::of::() From e6687f39d9d5250bbdbba5dff602fe9f2a1469b5 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sat, 16 Mar 2019 22:33:15 +0100 Subject: [PATCH 06/35] Don't report deprecation lints in derive expansions --- src/librustc/lint/mod.rs | 17 ++++++++++++++++- src/librustc/middle/stability.rs | 5 ++++- src/test/ui/deprecation/derive_on_deprecated.rs | 9 +++++++++ .../derive_on_deprecated_forbidden.rs | 9 +++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/deprecation/derive_on_deprecated.rs create mode 100644 src/test/ui/deprecation/derive_on_deprecated_forbidden.rs diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 6c60f3f5a80a3..f2ce9534b507c 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -812,7 +812,8 @@ pub fn provide(providers: &mut Providers<'_>) { /// Returns whether `span` originates in a foreign crate's external macro. /// -/// This is used to test whether a lint should be entirely aborted above. +/// This is used to test whether a lint should not even begin to figure out whether it should +/// be reported on the current node. pub fn in_external_macro(sess: &Session, span: Span) -> bool { let info = match span.ctxt().outer().expn_info() { Some(info) => info, @@ -838,3 +839,17 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool { Err(_) => true, } } + +/// Returns whether `span` originates in a derive macro's expansion +pub fn in_derive_expansion(span: Span) -> bool { + let info = match span.ctxt().outer().expn_info() { + Some(info) => info, + // no ExpnInfo means this span doesn't come from a macro + None => return false, + }; + + match info.format { + ExpnFormat::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("), + _ => false, + } +} diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 1190103d849ec..62a9e9e5d9055 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -3,7 +3,7 @@ pub use self::StabilityLevel::*; -use crate::lint::{self, Lint}; +use crate::lint::{self, Lint, in_derive_expansion}; use crate::hir::{self, Item, Generics, StructField, Variant, HirId}; use crate::hir::def::Def; use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE}; @@ -571,6 +571,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { suggestion: Option, message: &str, lint: &'static Lint| { + if in_derive_expansion(span) { + return; + } let msg = if let Some(note) = note { format!("{}: {}", message, note) } else { diff --git a/src/test/ui/deprecation/derive_on_deprecated.rs b/src/test/ui/deprecation/derive_on_deprecated.rs new file mode 100644 index 0000000000000..4980a7f5aa31c --- /dev/null +++ b/src/test/ui/deprecation/derive_on_deprecated.rs @@ -0,0 +1,9 @@ +// compile-pass + +#![deny(deprecated)] + +#[deprecated = "oh no"] +#[derive(Default)] +struct X; + +fn main() {} diff --git a/src/test/ui/deprecation/derive_on_deprecated_forbidden.rs b/src/test/ui/deprecation/derive_on_deprecated_forbidden.rs new file mode 100644 index 0000000000000..235146bad9c85 --- /dev/null +++ b/src/test/ui/deprecation/derive_on_deprecated_forbidden.rs @@ -0,0 +1,9 @@ +// compile-pass + +#![forbid(deprecated)] + +#[deprecated = "oh no"] +#[derive(Default)] +struct X; + +fn main() {} From 65cce683cab4e5b60615901c8dfcf6bb874cf048 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Wed, 30 Jan 2019 19:42:37 -0500 Subject: [PATCH 07/35] Started expanding docs for `TryFrom` and `TryInto`. The examples are still lacking for now, both for module docs and for methods/impl's. --- src/libcore/convert.rs | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 5ecfa9cde032e..a3f1a3201f318 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -366,6 +366,11 @@ pub trait From: Sized { /// provides an equivalent `TryInto` implementation for free, thanks to a /// blanket implementation in the standard library. For more information on this, /// see the documentation for [`Into`]. +/// +/// # Implementing `TryInto` +/// +/// This suffers the same restrictions and reasoning as implementing +/// [`Into`], see there for details. /// /// [`TryFrom`]: trait.TryFrom.html /// [`Into`]: trait.Into.html @@ -380,7 +385,44 @@ pub trait TryInto: Sized { fn try_into(self) -> Result; } -/// Attempt to construct `Self` via a conversion. +/// Simple and safe type conversions that may fail in a controlled +/// way under some circumstances. It is the reciprocal of [`TryInto`]. +/// +/// This is useful when you are doing a type conversion that may +/// trivially succeed but may also need special handling. +/// For example, there is no way to convert an `i64` into an `i32` +/// using the [`From`] trait, because an `i64` may contain a value +/// that an `i32` cannot represent and so the conversion would lose data. +/// This might be handled by truncating the `i64` to an `i32` (essentially +/// giving the `i64`'s value modulo `i32::MAX`) or by simply returning +/// `i32::MAX`, or by some other method. The `From` trait is intended +/// for lossless conversions, so the `TryFrom` trait informs the +/// programmer when a type conversion could go bad and lets them +/// decide how to handle it. +/// +/// # Generic Implementations +/// +/// - `TryFrom for U` implies [`TryInto`]` for T` +/// - [`try_from`] is reflexive, which means that `TryFrom for T` +/// is implemented +/// +/// # Examples +/// +/// As described, [`i32`] implements `TryFrom`: +/// +/// ``` +/// let big_number = 1_000_000_000_000i64; +/// // Silently truncates `big_number`, requires detecting +/// // and handling the truncation after the fact. +/// let smaller_number = big_number as i32; +/// assert_eq!(smaller_number, -727379968); +/// +/// let try_smaller_number = i32::try_from(big_number); +/// assert!(try_smaller_number.is_err()); +/// +/// let try_successful_smaller_number = i32::try_from(3); +/// assert!(try_successful_smaller_number.is_ok()); +/// ``` #[stable(feature = "try_from", since = "1.34.0")] pub trait TryFrom: Sized { /// The type returned in the event of a conversion error. From ad93f05643ea15a79529f3b7550b49f2b539a471 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Wed, 30 Jan 2019 20:19:01 -0500 Subject: [PATCH 08/35] Add basic docs to integer TryFrom impl macros. They're not as good as `From` 'cause they don't stringify the types and generate examples and so on, but it's a start. --- src/libcore/num/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 3ceba83afeef8..39a1b48e0766e 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4544,6 +4544,9 @@ macro_rules! try_from_unbounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; + /// Try to create the target type from the source type. + /// This particular variant will never fail, but is included + /// for completeness's sake. #[inline] fn try_from(value: $source) -> Result { Ok(value as $target) @@ -4559,6 +4562,10 @@ macro_rules! try_from_lower_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; + /// Try to create a target number type from a + /// source type that has `source::MIN > dest::MIN`. + /// Will return an error if `source` is less than + /// `dest::MIN`. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { if u >= 0 { @@ -4578,6 +4585,10 @@ macro_rules! try_from_upper_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; + /// Try to create a target number type from a + /// source type that has `source::MAX > dest::MAX`. + /// Will return an error if `source` is greater than + /// `dest::MAX`. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { if u > (<$target>::max_value() as $source) { @@ -4597,6 +4608,11 @@ macro_rules! try_from_both_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; + /// Try to "narrow" a number from the source type + /// to the target type. Will return an error if + /// the source value is either larger than the + /// `MAX` value for the target type or smaller + /// than the `MIN` value for it. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { let min = <$target>::min_value() as $source; From e26fc87a70fd139364faa43264719e4583d1dca6 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Thu, 31 Jan 2019 21:47:18 -0500 Subject: [PATCH 09/35] Fix a bunch of heckin' trailing whitespace --- src/libcore/convert.rs | 24 ++++++++++++------------ src/libcore/num/mod.rs | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index a3f1a3201f318..f64f2fb3e9faa 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -366,9 +366,9 @@ pub trait From: Sized { /// provides an equivalent `TryInto` implementation for free, thanks to a /// blanket implementation in the standard library. For more information on this, /// see the documentation for [`Into`]. -/// +/// /// # Implementing `TryInto` -/// +/// /// This suffers the same restrictions and reasoning as implementing /// [`Into`], see there for details. /// @@ -387,25 +387,25 @@ pub trait TryInto: Sized { /// Simple and safe type conversions that may fail in a controlled /// way under some circumstances. It is the reciprocal of [`TryInto`]. -/// -/// This is useful when you are doing a type conversion that may +/// +/// This is useful when you are doing a type conversion that may /// trivially succeed but may also need special handling. /// For example, there is no way to convert an `i64` into an `i32` /// using the [`From`] trait, because an `i64` may contain a value /// that an `i32` cannot represent and so the conversion would lose data. /// This might be handled by truncating the `i64` to an `i32` (essentially -/// giving the `i64`'s value modulo `i32::MAX`) or by simply returning -/// `i32::MAX`, or by some other method. The `From` trait is intended -/// for lossless conversions, so the `TryFrom` trait informs the +/// giving the `i64`'s value modulo `i32::MAX`) or by simply returning +/// `i32::MAX`, or by some other method. The `From` trait is intended +/// for lossless conversions, so the `TryFrom` trait informs the /// programmer when a type conversion could go bad and lets them /// decide how to handle it. -/// +/// /// # Generic Implementations /// /// - `TryFrom for U` implies [`TryInto`]` for T` -/// - [`try_from`] is reflexive, which means that `TryFrom for T` +/// - [`try_from`] is reflexive, which means that `TryFrom for T` /// is implemented -/// +/// /// # Examples /// /// As described, [`i32`] implements `TryFrom`: @@ -416,10 +416,10 @@ pub trait TryInto: Sized { /// // and handling the truncation after the fact. /// let smaller_number = big_number as i32; /// assert_eq!(smaller_number, -727379968); -/// +/// /// let try_smaller_number = i32::try_from(big_number); /// assert!(try_smaller_number.is_err()); -/// +/// /// let try_successful_smaller_number = i32::try_from(3); /// assert!(try_successful_smaller_number.is_ok()); /// ``` diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 39a1b48e0766e..d8e230abaf9b9 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4564,7 +4564,7 @@ macro_rules! try_from_lower_bounded { /// Try to create a target number type from a /// source type that has `source::MIN > dest::MIN`. - /// Will return an error if `source` is less than + /// Will return an error if `source` is less than /// `dest::MIN`. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { @@ -4587,7 +4587,7 @@ macro_rules! try_from_upper_bounded { /// Try to create a target number type from a /// source type that has `source::MAX > dest::MAX`. - /// Will return an error if `source` is greater than + /// Will return an error if `source` is greater than /// `dest::MAX`. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { @@ -4609,9 +4609,9 @@ macro_rules! try_from_both_bounded { type Error = TryFromIntError; /// Try to "narrow" a number from the source type - /// to the target type. Will return an error if - /// the source value is either larger than the - /// `MAX` value for the target type or smaller + /// to the target type. Will return an error if + /// the source value is either larger than the + /// `MAX` value for the target type or smaller /// than the `MIN` value for it. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { From 4c872a63a8f499a8aed671daa5d36c1638e5eb6e Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Wed, 13 Feb 2019 12:52:35 -0500 Subject: [PATCH 10/35] Fix some links in TryFrom docs. --- src/libcore/convert.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index f64f2fb3e9faa..4716aea1cdd50 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -361,11 +361,12 @@ pub trait From: Sized { /// An attempted conversion that consumes `self`, which may or may not be /// expensive. /// -/// Library authors should not directly implement this trait, but should prefer -/// implementing the [`TryFrom`] trait, which offers greater flexibility and -/// provides an equivalent `TryInto` implementation for free, thanks to a -/// blanket implementation in the standard library. For more information on this, -/// see the documentation for [`Into`]. +/// Library authors should usually not directly implement this trait, +/// but should prefer implementing the [`TryFrom`] trait, which offers +/// greater flexibility and provides an equivalent `TryInto` +/// implementation for free, thanks to a blanket implementation in the +/// standard library. For more information on this, see the +/// documentation for [`Into`]. /// /// # Implementing `TryInto` /// @@ -396,7 +397,7 @@ pub trait TryInto: Sized { /// This might be handled by truncating the `i64` to an `i32` (essentially /// giving the `i64`'s value modulo `i32::MAX`) or by simply returning /// `i32::MAX`, or by some other method. The `From` trait is intended -/// for lossless conversions, so the `TryFrom` trait informs the +/// for perfect conversions, so the `TryFrom` trait informs the /// programmer when a type conversion could go bad and lets them /// decide how to handle it. /// @@ -404,7 +405,8 @@ pub trait TryInto: Sized { /// /// - `TryFrom for U` implies [`TryInto`]` for T` /// - [`try_from`] is reflexive, which means that `TryFrom for T` -/// is implemented +/// is implemented and cannot fail -- the associated `Error` type for +/// calling `T::try_from()` on a value of type `T` is `!`. /// /// # Examples /// @@ -417,12 +419,18 @@ pub trait TryInto: Sized { /// let smaller_number = big_number as i32; /// assert_eq!(smaller_number, -727379968); /// +/// // Returns an error because `big_number` is too big to +/// // fit in an `i32`. /// let try_smaller_number = i32::try_from(big_number); /// assert!(try_smaller_number.is_err()); /// +/// // Returns `Ok(3)`. /// let try_successful_smaller_number = i32::try_from(3); /// assert!(try_successful_smaller_number.is_ok()); /// ``` +/// +/// [`try_from`]: trait.TryFrom.html#tymethod.try_from +/// [`TryInto`]: trait.TryInto.html #[stable(feature = "try_from", since = "1.34.0")] pub trait TryFrom: Sized { /// The type returned in the event of a conversion error. From 7a5739f525206cbe71015dacac5e426bba06c0a9 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Thu, 14 Feb 2019 09:19:03 -0500 Subject: [PATCH 11/35] Slowly figuring out how rustdoc actually works. Unfortunately trying to run doctests on my local machine is not really faster than letting Travis do it... --- src/libcore/convert.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 4716aea1cdd50..a9d1d01ccbb41 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -413,6 +413,9 @@ pub trait TryInto: Sized { /// As described, [`i32`] implements `TryFrom`: /// /// ``` +/// #![feature(try_from)] +/// use std::convert::TryFrom; +/// /// let big_number = 1_000_000_000_000i64; /// // Silently truncates `big_number`, requires detecting /// // and handling the truncation after the fact. From 7b39be2cf240f3f209d4e69d439c24693acc98d5 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Tue, 26 Feb 2019 23:47:55 -0500 Subject: [PATCH 12/35] Incorporated review changes. --- src/libcore/convert.rs | 4 +++- src/libcore/num/mod.rs | 48 ++++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index a9d1d01ccbb41..0fc182348c6c2 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -406,7 +406,9 @@ pub trait TryInto: Sized { /// - `TryFrom for U` implies [`TryInto`]` for T` /// - [`try_from`] is reflexive, which means that `TryFrom for T` /// is implemented and cannot fail -- the associated `Error` type for -/// calling `T::try_from()` on a value of type `T` is `!`. +/// calling `T::try_from()` on a value of type `T` is `Infallible`. +/// When the `!` type is stablized `Infallible` and `!` will be +/// equivalent. /// /// # Examples /// diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index d8e230abaf9b9..4a2f958b93fe7 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4544,9 +4544,14 @@ macro_rules! try_from_unbounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; - /// Try to create the target type from the source type. - /// This particular variant will never fail, but is included - /// for completeness's sake. + /// Try to create the target number type from a source + /// number type. If the source type has a larger range + /// than the target, or their ranges are disjoint (such + /// as converting a signed to unsigned number or vice + /// versa), this will return `None` if the source value + /// doesn't fit into the range of the destination value. + /// If the conversion can never fail, this is still + /// implemented for completeness's sake. #[inline] fn try_from(value: $source) -> Result { Ok(value as $target) @@ -4562,10 +4567,14 @@ macro_rules! try_from_lower_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; - /// Try to create a target number type from a - /// source type that has `source::MIN > dest::MIN`. - /// Will return an error if `source` is less than - /// `dest::MIN`. + /// Try to create the target number type from a source + /// number type. If the source type has a larger range + /// than the target, or their ranges are disjoint (such + /// as converting a signed to unsigned number or vice + /// versa), this will return `None` if the source value + /// doesn't fit into the range of the destination value. + /// If the conversion can never fail, this is still + /// implemented for completeness's sake. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { if u >= 0 { @@ -4585,10 +4594,14 @@ macro_rules! try_from_upper_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; - /// Try to create a target number type from a - /// source type that has `source::MAX > dest::MAX`. - /// Will return an error if `source` is greater than - /// `dest::MAX`. + /// Try to create the target number type from a source + /// number type. If the source type has a larger range + /// than the target, or their ranges are disjoint (such + /// as converting a signed to unsigned number or vice + /// versa), this will return `None` if the source value + /// doesn't fit into the range of the destination value. + /// If the conversion can never fail, this is still + /// implemented for completeness's sake. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { if u > (<$target>::max_value() as $source) { @@ -4608,11 +4621,14 @@ macro_rules! try_from_both_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; - /// Try to "narrow" a number from the source type - /// to the target type. Will return an error if - /// the source value is either larger than the - /// `MAX` value for the target type or smaller - /// than the `MIN` value for it. + /// Try to create the target number type from a source + /// number type. If the source type has a larger range + /// than the target, or their ranges are disjoint (such + /// as converting a signed to unsigned number or vice + /// versa), this will return `None` if the source value + /// doesn't fit into the range of the destination value. + /// If the conversion can never fail, this is still + /// implemented for completeness's sake. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { let min = <$target>::min_value() as $source; From a5b7384886e62faa4970e369932d3c89c6bf02ad Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Wed, 27 Feb 2019 09:54:37 -0500 Subject: [PATCH 13/35] Vastly simplify TryFrom docs. --- src/libcore/num/mod.rs | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 4a2f958b93fe7..d08aa079dbd11 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4545,13 +4545,8 @@ macro_rules! try_from_unbounded { type Error = TryFromIntError; /// Try to create the target number type from a source - /// number type. If the source type has a larger range - /// than the target, or their ranges are disjoint (such - /// as converting a signed to unsigned number or vice - /// versa), this will return `None` if the source value - /// doesn't fit into the range of the destination value. - /// If the conversion can never fail, this is still - /// implemented for completeness's sake. + /// number type. This returns an error if the source value + /// is outside of the range of the target type. #[inline] fn try_from(value: $source) -> Result { Ok(value as $target) @@ -4568,13 +4563,8 @@ macro_rules! try_from_lower_bounded { type Error = TryFromIntError; /// Try to create the target number type from a source - /// number type. If the source type has a larger range - /// than the target, or their ranges are disjoint (such - /// as converting a signed to unsigned number or vice - /// versa), this will return `None` if the source value - /// doesn't fit into the range of the destination value. - /// If the conversion can never fail, this is still - /// implemented for completeness's sake. + /// number type. This returns an error if the source value + /// is outside of the range of the target type. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { if u >= 0 { @@ -4595,13 +4585,8 @@ macro_rules! try_from_upper_bounded { type Error = TryFromIntError; /// Try to create the target number type from a source - /// number type. If the source type has a larger range - /// than the target, or their ranges are disjoint (such - /// as converting a signed to unsigned number or vice - /// versa), this will return `None` if the source value - /// doesn't fit into the range of the destination value. - /// If the conversion can never fail, this is still - /// implemented for completeness's sake. + /// number type. This returns an error if the source value + /// is outside of the range of the target type. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { if u > (<$target>::max_value() as $source) { @@ -4622,13 +4607,8 @@ macro_rules! try_from_both_bounded { type Error = TryFromIntError; /// Try to create the target number type from a source - /// number type. If the source type has a larger range - /// than the target, or their ranges are disjoint (such - /// as converting a signed to unsigned number or vice - /// versa), this will return `None` if the source value - /// doesn't fit into the range of the destination value. - /// If the conversion can never fail, this is still - /// implemented for completeness's sake. + /// number type. This returns an error if the source value + /// is outside of the range of the target type. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { let min = <$target>::min_value() as $source; From 079618dfcd56feadbd3497aa03b230178b9987e8 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 12 Mar 2019 17:42:42 +0100 Subject: [PATCH 14/35] Remove stabilized feature gate in doctest --- src/libcore/convert.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 0fc182348c6c2..774d648558b48 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -415,7 +415,6 @@ pub trait TryInto: Sized { /// As described, [`i32`] implements `TryFrom`: /// /// ``` -/// #![feature(try_from)] /// use std::convert::TryFrom; /// /// let big_number = 1_000_000_000_000i64; From edf0ecfc0c6fc586f7456e986549cb6fefaec474 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Sun, 7 Apr 2019 13:52:33 +0200 Subject: [PATCH 15/35] ci: pin android emulator to 28.0.23 --- src/ci/docker/arm-android/Dockerfile | 2 +- src/ci/docker/scripts/android-sdk.sh | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/arm-android/Dockerfile b/src/ci/docker/arm-android/Dockerfile index e10ccd56a4a54..bbf700ae2339f 100644 --- a/src/ci/docker/arm-android/Dockerfile +++ b/src/ci/docker/arm-android/Dockerfile @@ -23,7 +23,7 @@ RUN dpkg --add-architecture i386 && \ COPY scripts/android-sdk.sh /scripts/ RUN . /scripts/android-sdk.sh && \ - download_and_create_avd 4333796 armeabi-v7a 18 + download_and_create_avd 4333796 armeabi-v7a 18 5264690 ENV PATH=$PATH:/android/sdk/emulator ENV PATH=$PATH:/android/sdk/tools diff --git a/src/ci/docker/scripts/android-sdk.sh b/src/ci/docker/scripts/android-sdk.sh index 179f63fc830a6..e78e3795c046a 100644 --- a/src/ci/docker/scripts/android-sdk.sh +++ b/src/ci/docker/scripts/android-sdk.sh @@ -20,11 +20,19 @@ download_sysimage() { # The output from sdkmanager is so noisy that it will occupy all of the 4 MB # log extremely quickly. Thus we must silence all output. yes | sdkmanager --licenses > /dev/null - yes | sdkmanager platform-tools emulator \ + yes | sdkmanager platform-tools \ "platforms;android-$api" \ "system-images;android-$api;default;$abi" > /dev/null } +download_emulator() { + # Download a pinned version of the emulator since upgrades can cause issues + curl -fo emulator.zip "https://dl.google.com/android/repository/emulator-linux-$1.zip" + rm -rf "${ANDROID_HOME}/emulator" + unzip -q emulator.zip -d "${ANDROID_HOME}" + rm -f emulator.zip +} + create_avd() { abi=$1 api=$2 @@ -40,11 +48,12 @@ download_and_create_avd() { download_sdk $1 download_sysimage $2 $3 create_avd $2 $3 + download_emulator $4 } # Usage: # -# setup_android_sdk 4333796 armeabi-v7a 18 +# download_and_create_avd 4333796 armeabi-v7a 18 5264690 # # 4333796 => # SDK tool version. @@ -53,3 +62,6 @@ download_and_create_avd() { # System image ABI # 18 => # Android API Level (18 = Android 4.3 = Jelly Bean MR2) +# 5264690 => +# Android Emulator version. +# Copy from the "build_id" in the `/android/sdk/emulator/emulator -version` output From 54563552025958569c9aa0cb514a584ec798247f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 4 Apr 2019 11:40:21 -0700 Subject: [PATCH 16/35] ci: Update FreeBSD tarball downloads These appear to have disappeared from the original server, so I acquired the contents from a different mirror and uploaded them to our S3 bucket --- src/ci/docker/scripts/freebsd-toolchain.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/scripts/freebsd-toolchain.sh b/src/ci/docker/scripts/freebsd-toolchain.sh index 04483e249257e..b1ac490a87823 100755 --- a/src/ci/docker/scripts/freebsd-toolchain.sh +++ b/src/ci/docker/scripts/freebsd-toolchain.sh @@ -1,4 +1,6 @@ #!/bin/bash +# ignore-tidy-linelength + set -eux arch=$1 @@ -55,7 +57,9 @@ for lib in c++ c_nonshared compiler_rt execinfo gcc pthread rt ssp_nonshared; do files_to_extract=("${files_to_extract[@]}" "./usr/lib/lib${lib}.*") done -URL=https://download.freebsd.org/ftp/releases/${freebsd_arch}/${freebsd_version}-RELEASE/base.txz +# Originally downloaded from: +# https://download.freebsd.org/ftp/releases/${freebsd_arch}/${freebsd_version}-RELEASE/base.txz +URL=https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2019-04-04-freebsd-${freebsd_arch}-${freebsd_version}-RELEASE-base.txz curl "$URL" | tar xJf - -C "$sysroot" --wildcards "${files_to_extract[@]}" # Fix up absolute symlinks from the system image. This can be removed From 16e2c163b9be2d15f48f616cd128b6f8cdf29839 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 17 Mar 2019 08:04:57 -0600 Subject: [PATCH 17/35] Update CI configuration for building Redox libraries --- src/ci/docker/disabled/dist-x86_64-redox/Dockerfile | 4 ++-- src/ci/docker/dist-various-1/install-x86_64-redox.sh | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/ci/docker/disabled/dist-x86_64-redox/Dockerfile b/src/ci/docker/disabled/dist-x86_64-redox/Dockerfile index f4c25f791bc39..11a3acd68e3e8 100644 --- a/src/ci/docker/disabled/dist-x86_64-redox/Dockerfile +++ b/src/ci/docker/disabled/dist-x86_64-redox/Dockerfile @@ -7,8 +7,8 @@ COPY scripts/crosstool-ng.sh /scripts/ RUN sh /scripts/crosstool-ng.sh WORKDIR /tmp -COPY cross/install-x86_64-redox.sh /tmp/ -RUN ./install-x86_64-redox.sh +COPY dist-various-1/install-x86_64-redox.sh /scripts/ +RUN sh /scripts/install-x86_64-redox.sh COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh diff --git a/src/ci/docker/dist-various-1/install-x86_64-redox.sh b/src/ci/docker/dist-various-1/install-x86_64-redox.sh index c39be14941c90..67c2c633cf313 100755 --- a/src/ci/docker/dist-various-1/install-x86_64-redox.sh +++ b/src/ci/docker/dist-various-1/install-x86_64-redox.sh @@ -3,11 +3,5 @@ set -ex -apt-get update -apt-get install -y --no-install-recommends software-properties-common apt-transport-https - -apt-key adv --batch --yes --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys AA12E97F0881517F -add-apt-repository -y 'deb https://static.redox-os.org/toolchain/apt /' - -apt-get update -apt-get install -y x86-64-unknown-redox-gcc +wget -O - https://static.redox-os.org/toolchain/x86_64-unknown-redox/relibc-install.tar.gz | \ +tar --extract --gzip --directory /usr/local From 0bf2164df69efebb79c7a1926b99ea35c58fc3ea Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 5 Apr 2019 13:53:43 +0200 Subject: [PATCH 18/35] Function arguments should never get promoted --- src/librustc_mir/transform/qualify_consts.rs | 2 +- src/test/ui/consts/const_arg_wrapper.rs | 10 ++++++++++ src/test/ui/consts/const_arg_wrapper.stderr | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/const_arg_wrapper.rs create mode 100644 src/test/ui/consts/const_arg_wrapper.stderr diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index f7b7754cea7bc..e9fafc1fd90bf 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -628,7 +628,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { per_local.insert(local); } } - cx.per_local[IsNotPromotable].insert(local); + cx.per_local[IsNotConst].insert(local); } LocalKind::Var if mode == Mode::Fn => { diff --git a/src/test/ui/consts/const_arg_wrapper.rs b/src/test/ui/consts/const_arg_wrapper.rs new file mode 100644 index 0000000000000..3804102966e57 --- /dev/null +++ b/src/test/ui/consts/const_arg_wrapper.rs @@ -0,0 +1,10 @@ +#[cfg(target_arch = "x86")] +use std::arch::x86::*; +#[cfg(target_arch = "x86_64")] +use std::arch::x86_64::*; + +unsafe fn pclmul(a: __m128i, b: __m128i, imm8: i32) -> __m128i { + _mm_clmulepi64_si128(a, b, imm8) //~ ERROR argument 3 is required to be a constant +} + +fn main() {} diff --git a/src/test/ui/consts/const_arg_wrapper.stderr b/src/test/ui/consts/const_arg_wrapper.stderr new file mode 100644 index 0000000000000..5d0cae8cc2a9e --- /dev/null +++ b/src/test/ui/consts/const_arg_wrapper.stderr @@ -0,0 +1,8 @@ +error: argument 3 is required to be a constant + --> $DIR/const_arg_wrapper.rs:7:5 + | +LL | _mm_clmulepi64_si128(a, b, imm8) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + From 2bc43d443eb842010ecc531b902677dd03090647 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 5 Apr 2019 13:56:52 +0200 Subject: [PATCH 19/35] Add more regression tests for accidental promotion --- src/librustc_mir/transform/qualify_consts.rs | 4 ++-- src/test/ui/consts/const_arg_local.rs | 11 +++++++++++ src/test/ui/consts/const_arg_local.stderr | 8 ++++++++ src/test/ui/consts/const_arg_promotable.rs | 10 ++++++++++ src/test/ui/consts/const_arg_promotable.stderr | 8 ++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/consts/const_arg_local.rs create mode 100644 src/test/ui/consts/const_arg_local.stderr create mode 100644 src/test/ui/consts/const_arg_promotable.rs create mode 100644 src/test/ui/consts/const_arg_promotable.stderr diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index e9fafc1fd90bf..b843c345df530 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -636,7 +636,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { } LocalKind::Temp if !temps[local].is_promotable() => { - cx.per_local[IsNotPromotable].insert(local); + cx.per_local[IsNotConst].insert(local); } _ => {} @@ -810,7 +810,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { // be replaced with calling `insert` to re-set the bit). if kind == LocalKind::Temp { if !self.temp_promotion_state[index].is_promotable() { - assert!(self.cx.per_local[IsNotPromotable].contains(index)); + assert!(self.cx.per_local[IsNotConst].contains(index)); } } } diff --git a/src/test/ui/consts/const_arg_local.rs b/src/test/ui/consts/const_arg_local.rs new file mode 100644 index 0000000000000..d85a7a3de4895 --- /dev/null +++ b/src/test/ui/consts/const_arg_local.rs @@ -0,0 +1,11 @@ +#[cfg(target_arch = "x86")] +use std::arch::x86::*; +#[cfg(target_arch = "x86_64")] +use std::arch::x86_64::*; + +unsafe fn pclmul(a: __m128i, b: __m128i) -> __m128i { + let imm8 = 3; + _mm_clmulepi64_si128(a, b, imm8) //~ ERROR argument 3 is required to be a constant +} + +fn main() {} diff --git a/src/test/ui/consts/const_arg_local.stderr b/src/test/ui/consts/const_arg_local.stderr new file mode 100644 index 0000000000000..4fc6e9bcf7dff --- /dev/null +++ b/src/test/ui/consts/const_arg_local.stderr @@ -0,0 +1,8 @@ +error: argument 3 is required to be a constant + --> $DIR/const_arg_local.rs:8:5 + | +LL | _mm_clmulepi64_si128(a, b, imm8) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/consts/const_arg_promotable.rs b/src/test/ui/consts/const_arg_promotable.rs new file mode 100644 index 0000000000000..5c463780ac8c1 --- /dev/null +++ b/src/test/ui/consts/const_arg_promotable.rs @@ -0,0 +1,10 @@ +#[cfg(target_arch = "x86")] +use std::arch::x86::*; +#[cfg(target_arch = "x86_64")] +use std::arch::x86_64::*; + +unsafe fn pclmul(a: __m128i, b: __m128i) -> __m128i { + _mm_clmulepi64_si128(a, b, *&mut 42) //~ ERROR argument 3 is required to be a constant +} + +fn main() {} diff --git a/src/test/ui/consts/const_arg_promotable.stderr b/src/test/ui/consts/const_arg_promotable.stderr new file mode 100644 index 0000000000000..f10052b6df069 --- /dev/null +++ b/src/test/ui/consts/const_arg_promotable.stderr @@ -0,0 +1,8 @@ +error: argument 3 is required to be a constant + --> $DIR/const_arg_promotable.rs:7:5 + | +LL | _mm_clmulepi64_si128(a, b, *&mut 42) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + From dcd5bb2ebf9b4d372ca9510b7ffe4f840d075657 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 5 Apr 2019 17:00:21 +0200 Subject: [PATCH 20/35] Update comment --- src/librustc_mir/transform/qualify_consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index b843c345df530..9142e8b72f9f2 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -802,7 +802,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { } } - // Ensure the `IsNotPromotable` qualification is preserved. + // Ensure the `IsNotConst` qualification is preserved. // NOTE(eddyb) this is actually unnecessary right now, as // we never replace the local's qualif, but we might in // the future, and so it serves to catch changes that unset From 8f9fe5a38830dac8fdfdb7ddeedf12a1be4e347e Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sun, 7 Apr 2019 21:46:39 +0200 Subject: [PATCH 21/35] Only run SIMD tests on x86 --- src/test/ui/consts/const_arg_local.rs | 2 ++ src/test/ui/consts/const_arg_local.stderr | 2 +- src/test/ui/consts/const_arg_promotable.rs | 2 ++ src/test/ui/consts/const_arg_promotable.stderr | 2 +- src/test/ui/consts/const_arg_wrapper.rs | 2 ++ src/test/ui/consts/const_arg_wrapper.stderr | 2 +- 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/const_arg_local.rs b/src/test/ui/consts/const_arg_local.rs index d85a7a3de4895..0da4b44a96839 100644 --- a/src/test/ui/consts/const_arg_local.rs +++ b/src/test/ui/consts/const_arg_local.rs @@ -1,3 +1,5 @@ +// only-x86_64 + #[cfg(target_arch = "x86")] use std::arch::x86::*; #[cfg(target_arch = "x86_64")] diff --git a/src/test/ui/consts/const_arg_local.stderr b/src/test/ui/consts/const_arg_local.stderr index 4fc6e9bcf7dff..197b2f082e5a0 100644 --- a/src/test/ui/consts/const_arg_local.stderr +++ b/src/test/ui/consts/const_arg_local.stderr @@ -1,5 +1,5 @@ error: argument 3 is required to be a constant - --> $DIR/const_arg_local.rs:8:5 + --> $DIR/const_arg_local.rs:10:5 | LL | _mm_clmulepi64_si128(a, b, imm8) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/const_arg_promotable.rs b/src/test/ui/consts/const_arg_promotable.rs index 5c463780ac8c1..25f45104d6aa1 100644 --- a/src/test/ui/consts/const_arg_promotable.rs +++ b/src/test/ui/consts/const_arg_promotable.rs @@ -1,3 +1,5 @@ +// only-x86_64 + #[cfg(target_arch = "x86")] use std::arch::x86::*; #[cfg(target_arch = "x86_64")] diff --git a/src/test/ui/consts/const_arg_promotable.stderr b/src/test/ui/consts/const_arg_promotable.stderr index f10052b6df069..5de3ee6654ad9 100644 --- a/src/test/ui/consts/const_arg_promotable.stderr +++ b/src/test/ui/consts/const_arg_promotable.stderr @@ -1,5 +1,5 @@ error: argument 3 is required to be a constant - --> $DIR/const_arg_promotable.rs:7:5 + --> $DIR/const_arg_promotable.rs:9:5 | LL | _mm_clmulepi64_si128(a, b, *&mut 42) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/const_arg_wrapper.rs b/src/test/ui/consts/const_arg_wrapper.rs index 3804102966e57..92ff264cd2b8e 100644 --- a/src/test/ui/consts/const_arg_wrapper.rs +++ b/src/test/ui/consts/const_arg_wrapper.rs @@ -1,3 +1,5 @@ +// only-x86_64 + #[cfg(target_arch = "x86")] use std::arch::x86::*; #[cfg(target_arch = "x86_64")] diff --git a/src/test/ui/consts/const_arg_wrapper.stderr b/src/test/ui/consts/const_arg_wrapper.stderr index 5d0cae8cc2a9e..4acf2f0f4d1e5 100644 --- a/src/test/ui/consts/const_arg_wrapper.stderr +++ b/src/test/ui/consts/const_arg_wrapper.stderr @@ -1,5 +1,5 @@ error: argument 3 is required to be a constant - --> $DIR/const_arg_wrapper.rs:7:5 + --> $DIR/const_arg_wrapper.rs:9:5 | LL | _mm_clmulepi64_si128(a, b, imm8) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From b3191a43488141032bc2bf1f0754632bfe9aef46 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Sun, 7 Apr 2019 23:09:45 +0200 Subject: [PATCH 22/35] bless the ui tests --- src/test/ui/consts/const_arg_local.stderr | 2 +- src/test/ui/consts/const_arg_promotable.stderr | 2 +- src/test/ui/consts/const_arg_wrapper.stderr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/const_arg_local.stderr b/src/test/ui/consts/const_arg_local.stderr index 197b2f082e5a0..75814de9ccb14 100644 --- a/src/test/ui/consts/const_arg_local.stderr +++ b/src/test/ui/consts/const_arg_local.stderr @@ -1,7 +1,7 @@ error: argument 3 is required to be a constant --> $DIR/const_arg_local.rs:10:5 | -LL | _mm_clmulepi64_si128(a, b, imm8) +LL | _mm_clmulepi64_si128(a, b, imm8) //~ ERROR argument 3 is required to be a constant | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/const_arg_promotable.stderr b/src/test/ui/consts/const_arg_promotable.stderr index 5de3ee6654ad9..8d017f2769b17 100644 --- a/src/test/ui/consts/const_arg_promotable.stderr +++ b/src/test/ui/consts/const_arg_promotable.stderr @@ -1,7 +1,7 @@ error: argument 3 is required to be a constant --> $DIR/const_arg_promotable.rs:9:5 | -LL | _mm_clmulepi64_si128(a, b, *&mut 42) +LL | _mm_clmulepi64_si128(a, b, *&mut 42) //~ ERROR argument 3 is required to be a constant | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/const_arg_wrapper.stderr b/src/test/ui/consts/const_arg_wrapper.stderr index 4acf2f0f4d1e5..b39154f19e3d2 100644 --- a/src/test/ui/consts/const_arg_wrapper.stderr +++ b/src/test/ui/consts/const_arg_wrapper.stderr @@ -1,7 +1,7 @@ error: argument 3 is required to be a constant --> $DIR/const_arg_wrapper.rs:9:5 | -LL | _mm_clmulepi64_si128(a, b, imm8) +LL | _mm_clmulepi64_si128(a, b, imm8) //~ ERROR argument 3 is required to be a constant | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error From 8aa5034fb6b8f6df60fe41b9ad73c64c604ad31b Mon Sep 17 00:00:00 2001 From: kennytm Date: Wed, 3 Apr 2019 22:46:42 +0800 Subject: [PATCH 23/35] Use `curl` instead of `wget`. --- src/ci/docker/dist-various-1/install-x86_64-redox.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/dist-various-1/install-x86_64-redox.sh b/src/ci/docker/dist-various-1/install-x86_64-redox.sh index 67c2c633cf313..339042bb6729a 100755 --- a/src/ci/docker/dist-various-1/install-x86_64-redox.sh +++ b/src/ci/docker/dist-various-1/install-x86_64-redox.sh @@ -3,5 +3,5 @@ set -ex -wget -O - https://static.redox-os.org/toolchain/x86_64-unknown-redox/relibc-install.tar.gz | \ +curl https://static.redox-os.org/toolchain/x86_64-unknown-redox/relibc-install.tar.gz | \ tar --extract --gzip --directory /usr/local From d9ddef3e6df21ab70589500419a114fbf28742e3 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 28 Mar 2019 19:51:05 +0100 Subject: [PATCH 24/35] fix broken download link in the armhf-gnu image --- src/ci/docker/armhf-gnu/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/armhf-gnu/Dockerfile b/src/ci/docker/armhf-gnu/Dockerfile index 2b7624d53ee05..e4c2097f970a9 100644 --- a/src/ci/docker/armhf-gnu/Dockerfile +++ b/src/ci/docker/armhf-gnu/Dockerfile @@ -71,7 +71,8 @@ COPY scripts/qemu-bare-bones-addentropy.c /tmp/addentropy.c RUN arm-linux-gnueabihf-gcc addentropy.c -o rootfs/addentropy -static # TODO: What is this?! -RUN curl -O http://ftp.nl.debian.org/debian/dists/jessie/main/installer-armhf/current/images/device-tree/vexpress-v2p-ca15-tc1.dtb +# Source of the file: https://github.com/vfdev-5/qemu-rpi2-vexpress/raw/master/vexpress-v2p-ca15-tc1.dtb +RUN curl -O https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/vexpress-v2p-ca15-tc1.dtb COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh From c806b60fe6867e0065aa70f58a534999a1a55891 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 9 Feb 2019 20:28:22 +0100 Subject: [PATCH 25/35] Add rustdoc JS non-std tests --- src/bootstrap/builder.rs | 1 + src/bootstrap/test.rs | 44 +++ src/test/rustdoc-js-not-std/basic.js | 7 + src/test/rustdoc-js-not-std/basic.rs | 1 + src/tools/rustdoc-js-not-std/tester.js | 365 +++++++++++++++++++++++++ src/tools/rustdoc-js/tester.js | 3 +- 6 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-js-not-std/basic.js create mode 100644 src/test/rustdoc-js-not-std/basic.rs create mode 100644 src/tools/rustdoc-js-not-std/tester.js diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 7e6c0a9f52aa2..71b9cd6f9fba4 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -406,6 +406,7 @@ impl<'a> Builder<'a> { test::Clippy, test::CompiletestTest, test::RustdocJS, + test::RustdocJSNotStd, test::RustdocTheme, // Run bootstrap close to the end as it's unlikely to fail test::Bootstrap, diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 51412f79c3d0c..7dcc10e8a0918 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -612,6 +612,50 @@ impl Step for RustdocJS { } } +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct RustdocJSNotStd { + pub host: Interned, + pub target: Interned, + pub compiler: Compiler, +} + +impl Step for RustdocJSNotStd { + type Output = (); + const DEFAULT: bool = true; + const ONLY_HOSTS: bool = true; + + fn should_run(run: ShouldRun) -> ShouldRun { + run.path("src/test/rustdoc-js-not-std") + } + + fn make_run(run: RunConfig) { + let compiler = run.builder.compiler(run.builder.top_stage, run.host); + run.builder.ensure(RustdocJSNotStd { + host: run.host, + target: run.target, + compiler, + }); + } + + fn run(self, builder: &Builder) { + if let Some(ref nodejs) = builder.config.nodejs { + let mut command = Command::new(nodejs); + command.args(&["src/tools/rustdoc-js-not-std/tester.js", + &*self.host, + builder.top_stage.to_string().as_str()]); + builder.ensure(crate::doc::Std { + target: self.target, + stage: builder.top_stage, + }); + builder.run(&mut command); + } else { + builder.info( + "No nodejs found, skipping \"src/test/rustdoc-js-not-std\" tests" + ); + } + } +} + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct RustdocUi { pub host: Interned, diff --git a/src/test/rustdoc-js-not-std/basic.js b/src/test/rustdoc-js-not-std/basic.js new file mode 100644 index 0000000000000..d99b23468b60c --- /dev/null +++ b/src/test/rustdoc-js-not-std/basic.js @@ -0,0 +1,7 @@ +const QUERY = 'Fo'; + +const EXPECTED = { + 'others': [ + { 'path': 'basic', 'name': 'Foo' }, + ], +}; diff --git a/src/test/rustdoc-js-not-std/basic.rs b/src/test/rustdoc-js-not-std/basic.rs new file mode 100644 index 0000000000000..4a835673a596b --- /dev/null +++ b/src/test/rustdoc-js-not-std/basic.rs @@ -0,0 +1 @@ +pub struct Foo; diff --git a/src/tools/rustdoc-js-not-std/tester.js b/src/tools/rustdoc-js-not-std/tester.js new file mode 100644 index 0000000000000..61490b2f48d03 --- /dev/null +++ b/src/tools/rustdoc-js-not-std/tester.js @@ -0,0 +1,365 @@ +const fs = require('fs'); +const { spawnSync } = require('child_process'); + +const TEST_FOLDER = 'src/test/rustdoc-js-not-std/'; + +function getNextStep(content, pos, stop) { + while (pos < content.length && content[pos] !== stop && + (content[pos] === ' ' || content[pos] === '\t' || content[pos] === '\n')) { + pos += 1; + } + if (pos >= content.length) { + return null; + } + if (content[pos] !== stop) { + return pos * -1; + } + return pos; +} + +// Stupid function extractor based on indent. Doesn't support block +// comments. If someone puts a ' or an " in a block comment this +// will blow up. Template strings are not tested and might also be +// broken. +function extractFunction(content, functionName) { + var indent = 0; + var splitter = "function " + functionName + "("; + + while (true) { + var start = content.indexOf(splitter); + if (start === -1) { + break; + } + var pos = start; + while (pos < content.length && content[pos] !== ')') { + pos += 1; + } + if (pos >= content.length) { + break; + } + pos = getNextStep(content, pos + 1, '{'); + if (pos === null) { + break; + } else if (pos < 0) { + content = content.slice(-pos); + continue; + } + while (pos < content.length) { + // Eat single-line comments + if (content[pos] === '/' && pos > 0 && content[pos-1] === '/') { + do { + pos += 1; + } while (pos < content.length && content[pos] !== '\n'); + + // Eat quoted strings + } else if (content[pos] === '"' || content[pos] === "'" || content[pos] === "`") { + var stop = content[pos]; + var is_escaped = false; + do { + if (content[pos] === '\\') { + pos += 2; + } else { + pos += 1; + } + } while (pos < content.length && + (content[pos] !== stop || content[pos - 1] === '\\')); + + // Otherwise, check for indent + } else if (content[pos] === '{') { + indent += 1; + } else if (content[pos] === '}') { + indent -= 1; + if (indent === 0) { + return content.slice(start, pos + 1); + } + } + pos += 1; + } + content = content.slice(start + 1); + } + return null; +} + +// Stupid function extractor for array. +function extractArrayVariable(content, arrayName) { + var splitter = "var " + arrayName; + while (true) { + var start = content.indexOf(splitter); + if (start === -1) { + break; + } + var pos = getNextStep(content, start, '='); + if (pos === null) { + break; + } else if (pos < 0) { + content = content.slice(-pos); + continue; + } + pos = getNextStep(content, pos, '['); + if (pos === null) { + break; + } else if (pos < 0) { + content = content.slice(-pos); + continue; + } + while (pos < content.length) { + if (content[pos] === '"' || content[pos] === "'") { + var stop = content[pos]; + do { + if (content[pos] === '\\') { + pos += 2; + } else { + pos += 1; + } + } while (pos < content.length && + (content[pos] !== stop || content[pos - 1] === '\\')); + } else if (content[pos] === ']' && + pos + 1 < content.length && + content[pos + 1] === ';') { + return content.slice(start, pos + 2); + } + pos += 1; + } + content = content.slice(start + 1); + } + return null; +} + +// Stupid function extractor for variable. +function extractVariable(content, varName) { + var splitter = "var " + varName; + while (true) { + var start = content.indexOf(splitter); + if (start === -1) { + break; + } + var pos = getNextStep(content, start, '='); + if (pos === null) { + break; + } else if (pos < 0) { + content = content.slice(-pos); + continue; + } + while (pos < content.length) { + if (content[pos] === '"' || content[pos] === "'") { + var stop = content[pos]; + do { + if (content[pos] === '\\') { + pos += 2; + } else { + pos += 1; + } + } while (pos < content.length && + (content[pos] !== stop || content[pos - 1] === '\\')); + } else if (content[pos] === ';') { + return content.slice(start, pos + 1); + } + pos += 1; + } + content = content.slice(start + 1); + } + return null; +} + +function loadContent(content) { + var Module = module.constructor; + var m = new Module(); + m._compile(content, "tmp.js"); + m.exports.ignore_order = content.indexOf("\n// ignore-order\n") !== -1 || + content.startsWith("// ignore-order\n"); + m.exports.exact_check = content.indexOf("\n// exact-check\n") !== -1 || + content.startsWith("// exact-check\n"); + m.exports.should_fail = content.indexOf("\n// should-fail\n") !== -1 || + content.startsWith("// should-fail\n"); + return m.exports; +} + +function readFile(filePath) { + return fs.readFileSync(filePath, 'utf8'); +} + +function loadThings(thingsToLoad, kindOfLoad, funcToCall, fileContent) { + var content = ''; + for (var i = 0; i < thingsToLoad.length; ++i) { + var tmp = funcToCall(fileContent, thingsToLoad[i]); + if (tmp === null) { + console.error('unable to find ' + kindOfLoad + ' "' + thingsToLoad[i] + '"'); + process.exit(1); + } + content += tmp; + content += 'exports.' + thingsToLoad[i] + ' = ' + thingsToLoad[i] + ';'; + } + return content; +} + +function lookForEntry(entry, data) { + for (var i = 0; i < data.length; ++i) { + var allGood = true; + for (var key in entry) { + if (!entry.hasOwnProperty(key)) { + continue; + } + var value = data[i][key]; + // To make our life easier, if there is a "parent" type, we add it to the path. + if (key === 'path' && data[i]['parent'] !== undefined) { + if (value.length > 0) { + value += '::' + data[i]['parent']['name']; + } else { + value = data[i]['parent']['name']; + } + } + if (value !== entry[key]) { + allGood = false; + break; + } + } + if (allGood === true) { + return i; + } + } + return null; +} + +function remove_docs(out_dir) { + spawnSync('rm', ['-rf', out_dir]); +} + +function build_docs(out_dir, rustdoc_path, file_to_document) { + remove_docs(out_dir); + var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]); + var s = ''; + if (c.error || c.stderr.length > 0) { + if (c.stderr.length > 0) { + s += '==> STDERR: ' + c.stderr + '\n'; + } + s += '==> ERROR: ' + c.error; + } + return s; +} + +function load_files(out_folder, crate) { + var mainJs = readFile(out_folder + "/main.js"); + var ALIASES = readFile(out_folder + "/aliases.js"); + var searchIndex = readFile(out_folder + "/search-index.js").split("\n"); + if (searchIndex[searchIndex.length - 1].length === 0) { + searchIndex.pop(); + } + searchIndex.pop(); + searchIndex = loadContent(searchIndex.join("\n") + '\nexports.searchIndex = searchIndex;'); + finalJS = ""; + + var arraysToLoad = ["itemTypes"]; + var variablesToLoad = ["MAX_LEV_DISTANCE", "MAX_RESULTS", + "GENERICS_DATA", "NAME", "INPUTS_DATA", "OUTPUT_DATA", + "TY_PRIMITIVE", "TY_KEYWORD", + "levenshtein_row2"]; + // execQuery first parameter is built in getQuery (which takes in the search input). + // execQuery last parameter is built in buildIndex. + // buildIndex requires the hashmap from search-index. + var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult", + "getQuery", "buildIndex", "execQuery", "execSearch"]; + + finalJS += 'window = { "currentCrate": "' + crate + '" };\n'; + finalJS += 'var rootPath = "../";\n'; + finalJS += ALIASES; + finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs); + finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs); + finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs); + + var loaded = loadContent(finalJS); + return [loaded, loaded.buildIndex(searchIndex.searchIndex)]; +} + +function main(argv) { + if (argv.length !== 4) { + console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]"); + return 1; + } + const toolchain = argv[2]; + const stage = argv[3]; + const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc'; + + var errors = 0; + + fs.readdirSync(TEST_FOLDER).forEach(function(file) { + if (!file.endsWith('.js')) { + return; + } + var test_name = file.substring(0, file.length - 3); + process.stdout.write('Checking "' + test_name + '" ... '); + var rust_file = TEST_FOLDER + test_name + '.rs'; + + if (!fs.existsSync(rust_file)) { + console.error("FAILED"); + console.error("==> Missing '" + test_name + ".rs' file..."); + errors += 1; + return; + } + + var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js-not-std/" + + test_name; + + var ret = build_docs(out_folder, rustdoc_path, rust_file); + if (ret.length > 0) { + console.error("FAILED"); + console.error(ret); + errors += 1; + return; + } + + var [loaded, index] = load_files(out_folder, test_name); + var loadedFile = loadContent(readFile(TEST_FOLDER + file) + + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); + const expected = loadedFile.EXPECTED; + const query = loadedFile.QUERY; + const filter_crate = loadedFile.FILTER_CRATE; + const ignore_order = loadedFile.ignore_order; + const exact_check = loadedFile.exact_check; + const should_fail = loadedFile.should_fail; + var results = loaded.execSearch(loaded.getQuery(query), index); + var error_text = []; + for (var key in expected) { + if (!expected.hasOwnProperty(key)) { + continue; + } + if (!results.hasOwnProperty(key)) { + error_text.push('==> Unknown key "' + key + '"'); + break; + } + var entry = expected[key]; + var prev_pos = -1; + for (var i = 0; i < entry.length; ++i) { + var entry_pos = lookForEntry(entry[i], results[key]); + if (entry_pos === null) { + error_text.push("==> Result not found in '" + key + "': '" + + JSON.stringify(entry[i]) + "'"); + } else if (exact_check === true && prev_pos + 1 !== entry_pos) { + error_text.push("==> Exact check failed at position " + (prev_pos + 1) + ": " + + "expected '" + JSON.stringify(entry[i]) + "' but found '" + + JSON.stringify(results[key][i]) + "'"); + } else if (ignore_order === false && entry_pos < prev_pos) { + error_text.push("==> '" + JSON.stringify(entry[i]) + "' was supposed to be " + + " before '" + JSON.stringify(results[key][entry_pos]) + "'"); + } else { + prev_pos = entry_pos; + } + } + } + if (error_text.length === 0 && should_fail === true) { + errors += 1; + console.error("FAILED"); + console.error("==> Test was supposed to fail but all items were found..."); + } else if (error_text.length !== 0 && should_fail === false) { + errors += 1; + console.error("FAILED"); + console.error(error_text.join("\n")); + } else { + // In this case, we remove the docs, no need to keep them around. + remove_docs(out_folder); + console.log("OK"); + } + }); + return errors; +} + +process.exit(main(process.argv)); diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index c41da93a98310..38fdcb4f468cf 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -221,7 +221,8 @@ function lookForEntry(entry, data) { function main(argv) { if (argv.length !== 3) { - console.error("Expected toolchain to check as argument (for example 'x86_64-apple-darwin'"); + console.error("Expected toolchain to check as argument (for example \ + 'x86_64-apple-darwin')"); return 1; } var toolchain = argv[2]; From e371df4f23b6fb7274ab3e30dc133fce53588dc7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 24 Feb 2019 00:08:43 +0100 Subject: [PATCH 26/35] Rename rustdoc js test suites --- src/bootstrap/builder.rs | 2 +- src/bootstrap/test.rs | 18 ++--- src/test/rustdoc-js-not-std/basic.js | 7 -- .../{rustdoc-js => rustdoc-js-std}/alias-1.js | 0 .../{rustdoc-js => rustdoc-js-std}/alias-2.js | 0 .../{rustdoc-js => rustdoc-js-std}/alias-3.js | 0 .../{rustdoc-js => rustdoc-js-std}/alias.js | 0 src/test/rustdoc-js-std/basic.js | 15 ++++ .../deduplication.js | 0 .../enum-option.js | 0 .../filter-crate.js | 0 .../fn-forget.js | 0 .../{rustdoc-js => rustdoc-js-std}/from_u.js | 0 .../{rustdoc-js => rustdoc-js-std}/keyword.js | 0 .../macro-check.js | 0 .../macro-print.js | 0 .../multi-query.js | 0 .../{rustdoc-js => rustdoc-js-std}/never.js | 0 .../{rustdoc-js => rustdoc-js-std}/quoted.js | 0 .../should-fail.js | 0 .../string-from_ut.js | 0 .../struct-vec.js | 0 .../{rustdoc-js => rustdoc-js-std}/vec-new.js | 0 src/test/rustdoc-js/basic.js | 12 +-- .../basic.rs | 0 .../tester.js | 74 ++++--------------- src/tools/rustdoc-js/tester.js | 65 +++++++++++++--- 27 files changed, 93 insertions(+), 100 deletions(-) delete mode 100644 src/test/rustdoc-js-not-std/basic.js rename src/test/{rustdoc-js => rustdoc-js-std}/alias-1.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/alias-2.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/alias-3.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/alias.js (100%) create mode 100644 src/test/rustdoc-js-std/basic.js rename src/test/{rustdoc-js => rustdoc-js-std}/deduplication.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/enum-option.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/filter-crate.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/fn-forget.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/from_u.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/keyword.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/macro-check.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/macro-print.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/multi-query.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/never.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/quoted.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/should-fail.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/string-from_ut.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/struct-vec.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/vec-new.js (100%) rename src/test/{rustdoc-js-not-std => rustdoc-js}/basic.rs (100%) rename src/tools/{rustdoc-js-not-std => rustdoc-js-std}/tester.js (83%) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 71b9cd6f9fba4..a471af257665f 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -405,7 +405,7 @@ impl<'a> Builder<'a> { test::Miri, test::Clippy, test::CompiletestTest, - test::RustdocJS, + test::RustdocJSStd, test::RustdocJSNotStd, test::RustdocTheme, // Run bootstrap close to the end as it's unlikely to fail diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 7dcc10e8a0918..c724d75c2dc06 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -574,22 +574,22 @@ impl Step for RustdocTheme { } #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct RustdocJS { +pub struct RustdocJSStd { pub host: Interned, pub target: Interned, } -impl Step for RustdocJS { +impl Step for RustdocJSStd { type Output = (); const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/test/rustdoc-js") + run.path("src/test/rustdoc-js-std") } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(RustdocJS { + run.builder.ensure(RustdocJSStd { host: run.host, target: run.target, }); @@ -598,7 +598,7 @@ impl Step for RustdocJS { fn run(self, builder: &Builder<'_>) { if let Some(ref nodejs) = builder.config.nodejs { let mut command = Command::new(nodejs); - command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]); + command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]); builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage, @@ -606,7 +606,7 @@ impl Step for RustdocJS { builder.run(&mut command); } else { builder.info( - "No nodejs found, skipping \"src/test/rustdoc-js\" tests" + "No nodejs found, skipping \"src/test/rustdoc-js-std\" tests" ); } } @@ -625,7 +625,7 @@ impl Step for RustdocJSNotStd { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/test/rustdoc-js-not-std") + run.path("src/test/rustdoc-js") } fn make_run(run: RunConfig) { @@ -640,7 +640,7 @@ impl Step for RustdocJSNotStd { fn run(self, builder: &Builder) { if let Some(ref nodejs) = builder.config.nodejs { let mut command = Command::new(nodejs); - command.args(&["src/tools/rustdoc-js-not-std/tester.js", + command.args(&["src/tools/rustdoc-js/tester.js", &*self.host, builder.top_stage.to_string().as_str()]); builder.ensure(crate::doc::Std { @@ -650,7 +650,7 @@ impl Step for RustdocJSNotStd { builder.run(&mut command); } else { builder.info( - "No nodejs found, skipping \"src/test/rustdoc-js-not-std\" tests" + "No nodejs found, skipping \"src/test/rustdoc-js\" tests" ); } } diff --git a/src/test/rustdoc-js-not-std/basic.js b/src/test/rustdoc-js-not-std/basic.js deleted file mode 100644 index d99b23468b60c..0000000000000 --- a/src/test/rustdoc-js-not-std/basic.js +++ /dev/null @@ -1,7 +0,0 @@ -const QUERY = 'Fo'; - -const EXPECTED = { - 'others': [ - { 'path': 'basic', 'name': 'Foo' }, - ], -}; diff --git a/src/test/rustdoc-js/alias-1.js b/src/test/rustdoc-js-std/alias-1.js similarity index 100% rename from src/test/rustdoc-js/alias-1.js rename to src/test/rustdoc-js-std/alias-1.js diff --git a/src/test/rustdoc-js/alias-2.js b/src/test/rustdoc-js-std/alias-2.js similarity index 100% rename from src/test/rustdoc-js/alias-2.js rename to src/test/rustdoc-js-std/alias-2.js diff --git a/src/test/rustdoc-js/alias-3.js b/src/test/rustdoc-js-std/alias-3.js similarity index 100% rename from src/test/rustdoc-js/alias-3.js rename to src/test/rustdoc-js-std/alias-3.js diff --git a/src/test/rustdoc-js/alias.js b/src/test/rustdoc-js-std/alias.js similarity index 100% rename from src/test/rustdoc-js/alias.js rename to src/test/rustdoc-js-std/alias.js diff --git a/src/test/rustdoc-js-std/basic.js b/src/test/rustdoc-js-std/basic.js new file mode 100644 index 0000000000000..824cac7108332 --- /dev/null +++ b/src/test/rustdoc-js-std/basic.js @@ -0,0 +1,15 @@ +const QUERY = 'String'; + +const EXPECTED = { + 'others': [ + { 'path': 'std::string', 'name': 'String' }, + { 'path': 'std::ffi', 'name': 'CString' }, + { 'path': 'std::ffi', 'name': 'OsString' }, + ], + 'in_args': [ + { 'path': 'std::str', 'name': 'eq' }, + ], + 'returned': [ + { 'path': 'std::string::String', 'name': 'add' }, + ], +}; diff --git a/src/test/rustdoc-js/deduplication.js b/src/test/rustdoc-js-std/deduplication.js similarity index 100% rename from src/test/rustdoc-js/deduplication.js rename to src/test/rustdoc-js-std/deduplication.js diff --git a/src/test/rustdoc-js/enum-option.js b/src/test/rustdoc-js-std/enum-option.js similarity index 100% rename from src/test/rustdoc-js/enum-option.js rename to src/test/rustdoc-js-std/enum-option.js diff --git a/src/test/rustdoc-js/filter-crate.js b/src/test/rustdoc-js-std/filter-crate.js similarity index 100% rename from src/test/rustdoc-js/filter-crate.js rename to src/test/rustdoc-js-std/filter-crate.js diff --git a/src/test/rustdoc-js/fn-forget.js b/src/test/rustdoc-js-std/fn-forget.js similarity index 100% rename from src/test/rustdoc-js/fn-forget.js rename to src/test/rustdoc-js-std/fn-forget.js diff --git a/src/test/rustdoc-js/from_u.js b/src/test/rustdoc-js-std/from_u.js similarity index 100% rename from src/test/rustdoc-js/from_u.js rename to src/test/rustdoc-js-std/from_u.js diff --git a/src/test/rustdoc-js/keyword.js b/src/test/rustdoc-js-std/keyword.js similarity index 100% rename from src/test/rustdoc-js/keyword.js rename to src/test/rustdoc-js-std/keyword.js diff --git a/src/test/rustdoc-js/macro-check.js b/src/test/rustdoc-js-std/macro-check.js similarity index 100% rename from src/test/rustdoc-js/macro-check.js rename to src/test/rustdoc-js-std/macro-check.js diff --git a/src/test/rustdoc-js/macro-print.js b/src/test/rustdoc-js-std/macro-print.js similarity index 100% rename from src/test/rustdoc-js/macro-print.js rename to src/test/rustdoc-js-std/macro-print.js diff --git a/src/test/rustdoc-js/multi-query.js b/src/test/rustdoc-js-std/multi-query.js similarity index 100% rename from src/test/rustdoc-js/multi-query.js rename to src/test/rustdoc-js-std/multi-query.js diff --git a/src/test/rustdoc-js/never.js b/src/test/rustdoc-js-std/never.js similarity index 100% rename from src/test/rustdoc-js/never.js rename to src/test/rustdoc-js-std/never.js diff --git a/src/test/rustdoc-js/quoted.js b/src/test/rustdoc-js-std/quoted.js similarity index 100% rename from src/test/rustdoc-js/quoted.js rename to src/test/rustdoc-js-std/quoted.js diff --git a/src/test/rustdoc-js/should-fail.js b/src/test/rustdoc-js-std/should-fail.js similarity index 100% rename from src/test/rustdoc-js/should-fail.js rename to src/test/rustdoc-js-std/should-fail.js diff --git a/src/test/rustdoc-js/string-from_ut.js b/src/test/rustdoc-js-std/string-from_ut.js similarity index 100% rename from src/test/rustdoc-js/string-from_ut.js rename to src/test/rustdoc-js-std/string-from_ut.js diff --git a/src/test/rustdoc-js/struct-vec.js b/src/test/rustdoc-js-std/struct-vec.js similarity index 100% rename from src/test/rustdoc-js/struct-vec.js rename to src/test/rustdoc-js-std/struct-vec.js diff --git a/src/test/rustdoc-js/vec-new.js b/src/test/rustdoc-js-std/vec-new.js similarity index 100% rename from src/test/rustdoc-js/vec-new.js rename to src/test/rustdoc-js-std/vec-new.js diff --git a/src/test/rustdoc-js/basic.js b/src/test/rustdoc-js/basic.js index 824cac7108332..d99b23468b60c 100644 --- a/src/test/rustdoc-js/basic.js +++ b/src/test/rustdoc-js/basic.js @@ -1,15 +1,7 @@ -const QUERY = 'String'; +const QUERY = 'Fo'; const EXPECTED = { 'others': [ - { 'path': 'std::string', 'name': 'String' }, - { 'path': 'std::ffi', 'name': 'CString' }, - { 'path': 'std::ffi', 'name': 'OsString' }, - ], - 'in_args': [ - { 'path': 'std::str', 'name': 'eq' }, - ], - 'returned': [ - { 'path': 'std::string::String', 'name': 'add' }, + { 'path': 'basic', 'name': 'Foo' }, ], }; diff --git a/src/test/rustdoc-js-not-std/basic.rs b/src/test/rustdoc-js/basic.rs similarity index 100% rename from src/test/rustdoc-js-not-std/basic.rs rename to src/test/rustdoc-js/basic.rs diff --git a/src/tools/rustdoc-js-not-std/tester.js b/src/tools/rustdoc-js-std/tester.js similarity index 83% rename from src/tools/rustdoc-js-not-std/tester.js rename to src/tools/rustdoc-js-std/tester.js index 61490b2f48d03..f49dd86c8c32d 100644 --- a/src/tools/rustdoc-js-not-std/tester.js +++ b/src/tools/rustdoc-js-std/tester.js @@ -1,7 +1,6 @@ const fs = require('fs'); -const { spawnSync } = require('child_process'); -const TEST_FOLDER = 'src/test/rustdoc-js-not-std/'; +const TEST_FOLDER = 'src/test/rustdoc-js-std/'; function getNextStep(content, pos, stop) { while (pos < content.length && content[pos] !== stop && @@ -220,27 +219,17 @@ function lookForEntry(entry, data) { return null; } -function remove_docs(out_dir) { - spawnSync('rm', ['-rf', out_dir]); -} - -function build_docs(out_dir, rustdoc_path, file_to_document) { - remove_docs(out_dir); - var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]); - var s = ''; - if (c.error || c.stderr.length > 0) { - if (c.stderr.length > 0) { - s += '==> STDERR: ' + c.stderr + '\n'; - } - s += '==> ERROR: ' + c.error; +function main(argv) { + if (argv.length !== 3) { + console.error("Expected toolchain to check as argument (for example \ + 'x86_64-apple-darwin')"); + return 1; } - return s; -} + var toolchain = argv[2]; -function load_files(out_folder, crate) { - var mainJs = readFile(out_folder + "/main.js"); - var ALIASES = readFile(out_folder + "/aliases.js"); - var searchIndex = readFile(out_folder + "/search-index.js").split("\n"); + var mainJs = readFile("build/" + toolchain + "/doc/main.js"); + var ALIASES = readFile("build/" + toolchain + "/doc/aliases.js"); + var searchIndex = readFile("build/" + toolchain + "/doc/search-index.js").split("\n"); if (searchIndex[searchIndex.length - 1].length === 0) { searchIndex.pop(); } @@ -259,7 +248,7 @@ function load_files(out_folder, crate) { var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult", "getQuery", "buildIndex", "execQuery", "execSearch"]; - finalJS += 'window = { "currentCrate": "' + crate + '" };\n'; + finalJS += 'window = { "currentCrate": "std" };\n'; finalJS += 'var rootPath = "../";\n'; finalJS += ALIASES; finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs); @@ -267,47 +256,11 @@ function load_files(out_folder, crate) { finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs); var loaded = loadContent(finalJS); - return [loaded, loaded.buildIndex(searchIndex.searchIndex)]; -} - -function main(argv) { - if (argv.length !== 4) { - console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]"); - return 1; - } - const toolchain = argv[2]; - const stage = argv[3]; - const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc'; + var index = loaded.buildIndex(searchIndex.searchIndex); var errors = 0; fs.readdirSync(TEST_FOLDER).forEach(function(file) { - if (!file.endsWith('.js')) { - return; - } - var test_name = file.substring(0, file.length - 3); - process.stdout.write('Checking "' + test_name + '" ... '); - var rust_file = TEST_FOLDER + test_name + '.rs'; - - if (!fs.existsSync(rust_file)) { - console.error("FAILED"); - console.error("==> Missing '" + test_name + ".rs' file..."); - errors += 1; - return; - } - - var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js-not-std/" + - test_name; - - var ret = build_docs(out_folder, rustdoc_path, rust_file); - if (ret.length > 0) { - console.error("FAILED"); - console.error(ret); - errors += 1; - return; - } - - var [loaded, index] = load_files(out_folder, test_name); var loadedFile = loadContent(readFile(TEST_FOLDER + file) + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); const expected = loadedFile.EXPECTED; @@ -317,6 +270,7 @@ function main(argv) { const exact_check = loadedFile.exact_check; const should_fail = loadedFile.should_fail; var results = loaded.execSearch(loaded.getQuery(query), index); + process.stdout.write('Checking "' + file + '" ... '); var error_text = []; for (var key in expected) { if (!expected.hasOwnProperty(key)) { @@ -354,8 +308,6 @@ function main(argv) { console.error("FAILED"); console.error(error_text.join("\n")); } else { - // In this case, we remove the docs, no need to keep them around. - remove_docs(out_folder); console.log("OK"); } }); diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index 38fdcb4f468cf..f7c15eaf1b07d 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const { spawnSync } = require('child_process'); const TEST_FOLDER = 'src/test/rustdoc-js/'; @@ -219,17 +220,22 @@ function lookForEntry(entry, data) { return null; } -function main(argv) { - if (argv.length !== 3) { - console.error("Expected toolchain to check as argument (for example \ - 'x86_64-apple-darwin')"); - return 1; +function build_docs(out_dir, rustdoc_path, file_to_document) { + var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]); + var s = ''; + if (c.error || c.stderr.length > 0) { + if (c.stderr.length > 0) { + s += '==> STDERR: ' + c.stderr + '\n'; + } + s += '==> ERROR: ' + c.error; } - var toolchain = argv[2]; + return s; +} - var mainJs = readFile("build/" + toolchain + "/doc/main.js"); - var ALIASES = readFile("build/" + toolchain + "/doc/aliases.js"); - var searchIndex = readFile("build/" + toolchain + "/doc/search-index.js").split("\n"); +function load_files(out_folder, crate) { + var mainJs = readFile(out_folder + "/main.js"); + var ALIASES = readFile(out_folder + "/aliases.js"); + var searchIndex = readFile(out_folder + "/search-index.js").split("\n"); if (searchIndex[searchIndex.length - 1].length === 0) { searchIndex.pop(); } @@ -248,7 +254,7 @@ function main(argv) { var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult", "getQuery", "buildIndex", "execQuery", "execSearch"]; - finalJS += 'window = { "currentCrate": "std" };\n'; + finalJS += 'window = { "currentCrate": "' + crate + '" };\n'; finalJS += 'var rootPath = "../";\n'; finalJS += ALIASES; finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs); @@ -256,11 +262,47 @@ function main(argv) { finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs); var loaded = loadContent(finalJS); - var index = loaded.buildIndex(searchIndex.searchIndex); + return [loaded, loaded.buildIndex(searchIndex.searchIndex)]; +} + +function main(argv) { + if (argv.length !== 4) { + console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]"); + return 1; + } + const toolchain = argv[2]; + const stage = argv[3]; + const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc'; var errors = 0; fs.readdirSync(TEST_FOLDER).forEach(function(file) { + if (!file.endsWith('.js')) { + return; + } + var test_name = file.substring(0, file.length - 3); + process.stdout.write('Checking "' + test_name + '" ... '); + var rust_file = TEST_FOLDER + test_name + '.rs'; + + if (!fs.existsSync(rust_file)) { + console.error("FAILED"); + console.error("==> Missing '" + test_name + ".rs' file..."); + errors += 1; + return; + } + + var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js/" + + test_name; + + var ret = build_docs(out_folder, rustdoc_path, rust_file); + if (ret.length > 0) { + console.error("FAILED"); + console.error(ret); + errors += 1; + return; + } + + var [loaded, index] = load_files(out_folder, test_name); var loadedFile = loadContent(readFile(TEST_FOLDER + file) + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); const expected = loadedFile.EXPECTED; @@ -270,7 +312,6 @@ function main(argv) { const exact_check = loadedFile.exact_check; const should_fail = loadedFile.should_fail; var results = loaded.execSearch(loaded.getQuery(query), index); - process.stdout.write('Checking "' + file + '" ... '); var error_text = []; for (var key in expected) { if (!expected.hasOwnProperty(key)) { From 5f723239336e60a19c79bc89965cfe2f64dfec43 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 24 Feb 2019 01:04:07 +0100 Subject: [PATCH 27/35] Move documentation build into bootstrap --- src/bootstrap/test.rs | 46 ++++++++++++++++++++++++--- src/tools/rustdoc-js/tester.js | 58 ++++++++++------------------------ 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index c724d75c2dc06..83066468cd435 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -4,7 +4,7 @@ //! our CI. use std::env; -use std::ffi::OsString; +use std::ffi::{OsStr, OsString}; use std::fmt; use std::fs; use std::iter; @@ -639,14 +639,50 @@ impl Step for RustdocJSNotStd { fn run(self, builder: &Builder) { if let Some(ref nodejs) = builder.config.nodejs { - let mut command = Command::new(nodejs); - command.args(&["src/tools/rustdoc-js/tester.js", - &*self.host, - builder.top_stage.to_string().as_str()]); builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage, }); + + let mut tests_to_run = Vec::new(); + let out = Path::new("build").join(&*self.host) + .join(&format!("stage{}", + builder.top_stage.to_string().as_str())) + .join("tests") + .join("rustdoc-js"); + + if let Ok(it) = fs::read_dir("src/test/rustdoc-js/") { + for entry in it { + if let Ok(entry) = entry { + let path = entry.path(); + if path.extension() != Some(&OsStr::new("rs")) || !path.is_file() { + continue + } + let path_clone = path.clone(); + let file_stem = path_clone.file_stem().expect("cannot get file stem"); + let out = out.join(file_stem); + let mut cmd = builder.rustdoc_cmd(self.host); + cmd.arg("-o"); + cmd.arg(out); + cmd.arg(path); + if if builder.config.verbose_tests { + try_run(builder, &mut cmd) + } else { + try_run_quiet(builder, &mut cmd) + } { + tests_to_run.push(file_stem.to_os_string()); + } + } + } + } + assert!(!tests_to_run.is_empty(), "no rustdoc-js test generated..."); + + tests_to_run.insert(0, "src/tools/rustdoc-js/tester.js".into()); + tests_to_run.insert(1, out.into()); + + let mut command = Command::new(nodejs); + command.args(&tests_to_run); + builder.run(&mut command); } else { builder.info( diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index f7c15eaf1b07d..833ce5d137047 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -220,18 +220,6 @@ function lookForEntry(entry, data) { return null; } -function build_docs(out_dir, rustdoc_path, file_to_document) { - var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]); - var s = ''; - if (c.error || c.stderr.length > 0) { - if (c.stderr.length > 0) { - s += '==> STDERR: ' + c.stderr + '\n'; - } - s += '==> ERROR: ' + c.error; - } - return s; -} - function load_files(out_folder, crate) { var mainJs = readFile(out_folder + "/main.js"); var ALIASES = readFile(out_folder + "/aliases.js"); @@ -266,44 +254,32 @@ function load_files(out_folder, crate) { } function main(argv) { - if (argv.length !== 4) { - console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]"); + if (argv.length < 4) { + console.error("USAGE: node tester.js OUT_FOLDER [TESTS]"); return 1; } - const toolchain = argv[2]; - const stage = argv[3]; - const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc'; + if (argv[2].substr(-1) !== "/") { + argv[2] += "/"; + } + const out_folder = argv[2]; var errors = 0; - fs.readdirSync(TEST_FOLDER).forEach(function(file) { - if (!file.endsWith('.js')) { - return; - } - var test_name = file.substring(0, file.length - 3); - process.stdout.write('Checking "' + test_name + '" ... '); - var rust_file = TEST_FOLDER + test_name + '.rs'; + for (var j = 3; j < argv.length; ++j) { + const test_name = argv[j]; - if (!fs.existsSync(rust_file)) { - console.error("FAILED"); - console.error("==> Missing '" + test_name + ".rs' file..."); + process.stdout.write('Checking "' + test_name + '" ... '); + if (!fs.existsSync(TEST_FOLDER + test_name + ".js")) { errors += 1; - return; - } - - var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js/" + - test_name; - - var ret = build_docs(out_folder, rustdoc_path, rust_file); - if (ret.length > 0) { console.error("FAILED"); - console.error(ret); - errors += 1; - return; + console.error("==> Missing '" + test_name + ".js' file..."); + continue; } - var [loaded, index] = load_files(out_folder, test_name); - var loadedFile = loadContent(readFile(TEST_FOLDER + file) + + const test_out_folder = out_folder + test_name; + + var [loaded, index] = load_files(test_out_folder, test_name); + var loadedFile = loadContent(readFile(TEST_FOLDER + test_name + ".js") + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); const expected = loadedFile.EXPECTED; const query = loadedFile.QUERY; @@ -351,7 +327,7 @@ function main(argv) { } else { console.log("OK"); } - }); + } return errors; } From 33ed67420a0605c99d38cd1b840c2b481b27b018 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Feb 2019 17:47:12 +0100 Subject: [PATCH 28/35] Update to last updates --- src/bootstrap/test.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 83066468cd435..97a5c500b1a47 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -624,11 +624,11 @@ impl Step for RustdocJSNotStd { const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; - fn should_run(run: ShouldRun) -> ShouldRun { + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { run.path("src/test/rustdoc-js") } - fn make_run(run: RunConfig) { + fn make_run(run: RunConfig<'_>) { let compiler = run.builder.compiler(run.builder.top_stage, run.host); run.builder.ensure(RustdocJSNotStd { host: run.host, @@ -637,7 +637,7 @@ impl Step for RustdocJSNotStd { }); } - fn run(self, builder: &Builder) { + fn run(self, builder: &Builder<'_>) { if let Some(ref nodejs) = builder.config.nodejs { builder.ensure(crate::doc::Std { target: self.target, From 59d8883ec4f489922192f2472ad3141e6f92fa7a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 28 Feb 2019 18:08:48 +0100 Subject: [PATCH 29/35] Move rustdoc-js testing into compiletest --- src/bootstrap/test.rs | 62 ++++++---------------------- src/test/rustdoc-js/basic.rs | 1 + src/tools/compiletest/src/common.rs | 3 ++ src/tools/compiletest/src/runtest.rs | 29 +++++++++++-- 4 files changed, 42 insertions(+), 53 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 97a5c500b1a47..b7323b2eadc3d 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -4,7 +4,7 @@ //! our CI. use std::env; -use std::ffi::{OsStr, OsString}; +use std::ffi::OsString; use std::fmt; use std::fs; use std::iter; @@ -638,52 +638,15 @@ impl Step for RustdocJSNotStd { } fn run(self, builder: &Builder<'_>) { - if let Some(ref nodejs) = builder.config.nodejs { - builder.ensure(crate::doc::Std { + if builder.config.nodejs.is_some() { + builder.ensure(Compiletest { + compiler: self.compiler, target: self.target, - stage: builder.top_stage, + mode: "js-doc-test", + suite: "rustdoc-js", + path: None, + compare_mode: None, }); - - let mut tests_to_run = Vec::new(); - let out = Path::new("build").join(&*self.host) - .join(&format!("stage{}", - builder.top_stage.to_string().as_str())) - .join("tests") - .join("rustdoc-js"); - - if let Ok(it) = fs::read_dir("src/test/rustdoc-js/") { - for entry in it { - if let Ok(entry) = entry { - let path = entry.path(); - if path.extension() != Some(&OsStr::new("rs")) || !path.is_file() { - continue - } - let path_clone = path.clone(); - let file_stem = path_clone.file_stem().expect("cannot get file stem"); - let out = out.join(file_stem); - let mut cmd = builder.rustdoc_cmd(self.host); - cmd.arg("-o"); - cmd.arg(out); - cmd.arg(path); - if if builder.config.verbose_tests { - try_run(builder, &mut cmd) - } else { - try_run_quiet(builder, &mut cmd) - } { - tests_to_run.push(file_stem.to_os_string()); - } - } - } - } - assert!(!tests_to_run.is_empty(), "no rustdoc-js test generated..."); - - tests_to_run.insert(0, "src/tools/rustdoc-js/tester.js".into()); - tests_to_run.insert(1, out.into()); - - let mut command = Command::new(nodejs); - command.args(&tests_to_run); - - builder.run(&mut command); } else { builder.info( "No nodejs found, skipping \"src/test/rustdoc-js\" tests" @@ -1070,12 +1033,13 @@ impl Step for Compiletest { .arg(builder.sysroot_libdir(compiler, target)); cmd.arg("--rustc-path").arg(builder.rustc(compiler)); - let is_rustdoc_ui = suite.ends_with("rustdoc-ui"); + let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js"); // Avoid depending on rustdoc when we don't need it. if mode == "rustdoc" || (mode == "run-make" && suite.ends_with("fulldeps")) - || (mode == "ui" && is_rustdoc_ui) + || (mode == "ui" && is_rustdoc) + || mode == "js-doc-test" { cmd.arg("--rustdoc-path") .arg(builder.rustdoc(compiler.host)); @@ -1109,12 +1073,12 @@ impl Step for Compiletest { cmd.arg("--nodejs").arg(nodejs); } - let mut flags = if is_rustdoc_ui { + let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] }; - if !is_rustdoc_ui { + if !is_rustdoc { if builder.config.rust_optimize_tests { flags.push("-O".to_string()); } diff --git a/src/test/rustdoc-js/basic.rs b/src/test/rustdoc-js/basic.rs index 4a835673a596b..1b4963fcebea8 100644 --- a/src/test/rustdoc-js/basic.rs +++ b/src/test/rustdoc-js/basic.rs @@ -1 +1,2 @@ +/// Foo pub struct Foo; diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 6b3117a1f74f4..f0991c8cdb547 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -24,6 +24,7 @@ pub enum Mode { Incremental, RunMake, Ui, + JsDocTest, MirOpt, } @@ -59,6 +60,7 @@ impl FromStr for Mode { "incremental" => Ok(Incremental), "run-make" => Ok(RunMake), "ui" => Ok(Ui), + "js-doc-test" => Ok(JsDocTest), "mir-opt" => Ok(MirOpt), _ => Err(()), } @@ -82,6 +84,7 @@ impl fmt::Display for Mode { Incremental => "incremental", RunMake => "run-make", Ui => "ui", + JsDocTest => "js-doc-test", MirOpt => "mir-opt", }; fmt::Display::fmt(s, f) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index bac41a7c57904..f7c02e831a9aa 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -4,7 +4,7 @@ use crate::common::{output_base_dir, output_base_name, output_testname_unique}; use crate::common::{Codegen, CodegenUnits, DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Rustdoc}; use crate::common::{CompileFail, Pretty, RunFail, RunPass, RunPassValgrind}; use crate::common::{Config, TestPaths}; -use crate::common::{Incremental, MirOpt, RunMake, Ui}; +use crate::common::{Incremental, MirOpt, RunMake, Ui, JsDocTest}; use diff; use crate::errors::{self, Error, ErrorKind}; use filetime::FileTime; @@ -275,6 +275,7 @@ impl<'test> TestCx<'test> { RunMake => self.run_rmake_test(), RunPass | Ui => self.run_ui_test(), MirOpt => self.run_mir_opt_test(), + JsDocTest => self.run_js_doc_test(), } } @@ -290,7 +291,7 @@ impl<'test> TestCx<'test> { fn should_compile_successfully(&self) -> bool { match self.config.mode { CompileFail => self.props.compile_pass, - RunPass => true, + RunPass | JsDocTest => true, Ui => self.props.compile_pass, Incremental => { let revision = self.revision @@ -1712,7 +1713,8 @@ impl<'test> TestCx<'test> { } fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation) -> Command { - let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui"); + let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui") || + self.config.src_base.ends_with("rustdoc-js"); let mut rustc = if !is_rustdoc { Command::new(&self.config.rustc_path) } else { @@ -1802,7 +1804,7 @@ impl<'test> TestCx<'test> { rustc.arg(dir_opt); } RunFail | RunPassValgrind | Pretty | DebugInfoBoth | DebugInfoGdb | DebugInfoLldb - | Codegen | Rustdoc | RunMake | CodegenUnits => { + | Codegen | Rustdoc | RunMake | CodegenUnits | JsDocTest => { // do not use JSON output } } @@ -2710,6 +2712,25 @@ impl<'test> TestCx<'test> { fs::remove_dir(path) } + fn run_js_doc_test(&self) { + if let Some(nodejs) = &self.config.nodejs { + let out_dir = self.output_base_dir(); + + self.document(&out_dir); + + let root = self.config.find_rust_src_root().unwrap(); + let res = self.cmd2procres( + Command::new(&nodejs) + .arg(root.join("src/tools/rustdoc-js/tester.js")) + .arg(out_dir.parent().expect("no parent")) + .arg(&self.testpaths.file.file_stem().expect("couldn't get file stem")), + ); + if !res.status.success() { + self.fatal_proc_rec("rustdoc-js test failed!", &res); + } + } + } + fn run_ui_test(&self) { // if the user specified a format in the ui test // print the output to the stderr file, otherwise extract From 7837716929213e92ad4f9927a8b86444e98a6fb8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 6 Mar 2019 15:01:30 +0100 Subject: [PATCH 30/35] Improve code --- src/tools/compiletest/src/runtest.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f7c02e831a9aa..7781ce74f411e 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -291,7 +291,8 @@ impl<'test> TestCx<'test> { fn should_compile_successfully(&self) -> bool { match self.config.mode { CompileFail => self.props.compile_pass, - RunPass | JsDocTest => true, + RunPass => true, + JsDocTest => true, Ui => self.props.compile_pass, Incremental => { let revision = self.revision @@ -2728,6 +2729,8 @@ impl<'test> TestCx<'test> { if !res.status.success() { self.fatal_proc_rec("rustdoc-js test failed!", &res); } + } else { + self.fatal("no nodeJS"); } } From 2d61b579efe1872003ed9d08373388b4163b2f15 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 10 Mar 2019 23:10:40 +0100 Subject: [PATCH 31/35] Make js tests work even with resource-suffix option --- src/tools/rustdoc-js-std/tester.js | 33 +++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/tools/rustdoc-js-std/tester.js b/src/tools/rustdoc-js-std/tester.js index f49dd86c8c32d..d5f0ab9f4292d 100644 --- a/src/tools/rustdoc-js-std/tester.js +++ b/src/tools/rustdoc-js-std/tester.js @@ -219,6 +219,32 @@ function lookForEntry(entry, data) { return null; } +function findFile(dir, name, extension) { + var entries = fs.readdirSync(dir); + for (var i = 0; i < entries.length; ++i) { + var entry = entries[i]; + var file_type = fs.statSync(dir + entry); + if (file_type.isDirectory()) { + continue; + } + if (entry.startsWith(name) && entry.endsWith(extension)) { + return entry; + } + } + return null; +} + +function readFileMatching(dir, name, extension) { + if (dir.endsWith("/") === false) { + dir += "/"; + } + var f = findFile(dir, name, extension); + if (f === null) { + return ""; + } + return readFile(dir + f); +} + function main(argv) { if (argv.length !== 3) { console.error("Expected toolchain to check as argument (for example \ @@ -227,9 +253,10 @@ function main(argv) { } var toolchain = argv[2]; - var mainJs = readFile("build/" + toolchain + "/doc/main.js"); - var ALIASES = readFile("build/" + toolchain + "/doc/aliases.js"); - var searchIndex = readFile("build/" + toolchain + "/doc/search-index.js").split("\n"); + var mainJs = readFileMatching("build/" + toolchain + "/doc/", "main", ".js"); + var ALIASES = readFileMatching("build/" + toolchain + "/doc/", "aliases", ".js"); + var searchIndex = readFileMatching("build/" + toolchain + "/doc/", + "search-index", ".js").split("\n"); if (searchIndex[searchIndex.length - 1].length === 0) { searchIndex.pop(); } From 477bd6a1bf2601ba3074b07dfdf5bd6fde3c215e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 1 Mar 2019 17:03:15 +0100 Subject: [PATCH 32/35] Prevent cache issues on version updates --- src/bootstrap/doc.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 40f0e5ede8bd7..1891334ac2dd1 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -343,12 +343,10 @@ fn invoke_rustdoc( .arg("--html-before-content").arg(&version_info) .arg("--html-in-header").arg(&favicon) .arg("--markdown-no-toc") - .arg("--markdown-playground-url") - .arg("https://play.rust-lang.org/") - .arg("-o").arg(&out) - .arg(&path) - .arg("--markdown-css") - .arg("../rust.css"); + .arg("--resource-suffix").arg(crate::channel::CFG_RELEASE_NUM) + .arg("--markdown-playground-url").arg("https://play.rust-lang.org/") + .arg("-o").arg(&out).arg(&path) + .arg("--markdown-css").arg("../rust.css"); builder.run(&mut cmd); } @@ -430,9 +428,9 @@ impl Step for Standalone { .arg("--html-before-content").arg(&version_info) .arg("--html-in-header").arg(&favicon) .arg("--markdown-no-toc") + .arg("--resource-suffix").arg(crate::channel::CFG_RELEASE_NUM) .arg("--index-page").arg(&builder.src.join("src/doc/index.md")) - .arg("--markdown-playground-url") - .arg("https://play.rust-lang.org/") + .arg("--markdown-playground-url").arg("https://play.rust-lang.org/") .arg("-o").arg(&out) .arg(&path); @@ -523,6 +521,7 @@ impl Step for Std { .arg("--markdown-css").arg("rust.css") .arg("--markdown-no-toc") .arg("--generate-redirect-pages") + .arg("--resource-suffix").arg(crate::channel::CFG_RELEASE_NUM) .arg("--index-page").arg(&builder.src.join("src/doc/index.md")); builder.run(&mut cargo); From 5c8705dd9c4c2d307246b0caf42b66e9af6bc1e9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 13 Mar 2019 00:32:13 +0100 Subject: [PATCH 33/35] Add resource suffix for libtest and proc_macro as well --- src/bootstrap/doc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 1891334ac2dd1..d9ab8c6f1e5d7 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -343,7 +343,6 @@ fn invoke_rustdoc( .arg("--html-before-content").arg(&version_info) .arg("--html-in-header").arg(&favicon) .arg("--markdown-no-toc") - .arg("--resource-suffix").arg(crate::channel::CFG_RELEASE_NUM) .arg("--markdown-playground-url").arg("https://play.rust-lang.org/") .arg("-o").arg(&out).arg(&path) .arg("--markdown-css").arg("../rust.css"); @@ -428,7 +427,6 @@ impl Step for Standalone { .arg("--html-before-content").arg(&version_info) .arg("--html-in-header").arg(&favicon) .arg("--markdown-no-toc") - .arg("--resource-suffix").arg(crate::channel::CFG_RELEASE_NUM) .arg("--index-page").arg(&builder.src.join("src/doc/index.md")) .arg("--markdown-playground-url").arg("https://play.rust-lang.org/") .arg("-o").arg(&out) @@ -588,6 +586,7 @@ impl Step for Test { cargo.arg("--no-deps") .arg("-p").arg("test") + .env("RUSTDOC_RESOURCE_SUFFIX", crate::channel::CFG_RELEASE_NUM) .env("RUSTDOC_GENERATE_REDIRECT_PAGES", "1"); builder.run(&mut cargo); @@ -659,6 +658,7 @@ impl Step for WhitelistedRustc { // for which docs must be built. for krate in &["proc_macro"] { cargo.arg("-p").arg(krate) + .env("RUSTDOC_RESOURCE_SUFFIX", crate::channel::CFG_RELEASE_NUM) .env("RUSTDOC_GENERATE_REDIRECT_PAGES", "1"); } From 2db56c693c2426cadba06c2023569da4c6bad63d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Mar 2019 22:01:19 +0100 Subject: [PATCH 34/35] Handle RUSTDOC_RESOURCE_SUFFIX env variable for rustdoc build --- src/bootstrap/bin/rustdoc.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs index 36beec3a944a0..52b5971f0a67d 100644 --- a/src/bootstrap/bin/rustdoc.rs +++ b/src/bootstrap/bin/rustdoc.rs @@ -69,6 +69,17 @@ fn main() { .arg("unstable-options"); } cmd.arg("--generate-redirect-pages"); + has_unstable = true; + } + + // Needed to be able to run all rustdoc tests. + if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") { + // This "unstable-options" can be removed when `--resource-suffix` is stabilized + if !has_unstable { + cmd.arg("-Z") + .arg("unstable-options"); + } + cmd.arg("--resource-suffix").arg(x); } if verbose > 1 { From d05ef971224e96ffeee7d2137348d97cb5d4977a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 26 Mar 2019 23:57:16 +0100 Subject: [PATCH 35/35] Fix error index CSS file name --- src/bootstrap/doc.rs | 1 + src/tools/error_index_generator/main.rs | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index d9ab8c6f1e5d7..f81c64076ebab 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -885,6 +885,7 @@ impl Step for ErrorIndex { let mut index = builder.tool_cmd(Tool::ErrorIndex); index.arg("html"); index.arg(out.join("error-index.html")); + index.arg(crate::channel::CFG_RELEASE_NUM); // FIXME: shouldn't have to pass this env var index.env("CFG_BUILD", &builder.config.build) diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index faeeea605a2b4..04986b59ea0f1 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -27,9 +27,10 @@ enum OutputFormat { } impl OutputFormat { - fn from(format: &str) -> OutputFormat { + fn from(format: &str, resource_suffix: &str) -> OutputFormat { match &*format.to_lowercase() { - "html" => OutputFormat::HTML(HTMLFormatter(RefCell::new(IdMap::new()))), + "html" => OutputFormat::HTML(HTMLFormatter(RefCell::new(IdMap::new()), + resource_suffix.to_owned())), "markdown" => OutputFormat::Markdown(MarkdownFormatter), s => OutputFormat::Unknown(s.to_owned()), } @@ -44,7 +45,7 @@ trait Formatter { fn footer(&self, output: &mut dyn Write) -> Result<(), Box>; } -struct HTMLFormatter(RefCell); +struct HTMLFormatter(RefCell, String); struct MarkdownFormatter; impl Formatter for HTMLFormatter { @@ -55,7 +56,7 @@ impl Formatter for HTMLFormatter { Rust Compiler Error Index - + -"##)?; +"##, suffix=self.1)?; Ok(()) } @@ -242,9 +243,12 @@ fn main_with_result(format: OutputFormat, dst: &Path) -> Result<(), Box (OutputFormat, PathBuf) { let mut args = env::args().skip(1); - let format = args.next().map(|a| OutputFormat::from(&a)) - .unwrap_or(OutputFormat::from("html")); - let dst = args.next().map(PathBuf::from).unwrap_or_else(|| { + let format = args.next(); + let dst = args.next(); + let resource_suffix = args.next().unwrap_or_else(String::new); + let format = format.map(|a| OutputFormat::from(&a, &resource_suffix)) + .unwrap_or(OutputFormat::from("html", &resource_suffix)); + let dst = dst.map(PathBuf::from).unwrap_or_else(|| { match format { OutputFormat::HTML(..) => PathBuf::from("doc/error-index.html"), OutputFormat::Markdown(..) => PathBuf::from("doc/error-index.md"),