From 5ece5f9610652200f7805a238aabf28f5125d942 Mon Sep 17 00:00:00 2001 From: ishitatsuyuki Date: Thu, 31 Jan 2019 18:28:22 +0900 Subject: [PATCH 01/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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