diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index e25742a4a61eb..ec9b5eba56106 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -108,6 +108,7 @@ #![cfg_attr(stage0, feature(repr_transparent))] #![feature(rustc_attrs)] #![feature(specialization)] +#![feature(split_ascii_whitespace)] #![feature(staged_api)] #![feature(str_internals)] #![feature(trusted_len)] diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 32ca8d1fa5eba..ec9c39c916c47 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -78,6 +78,8 @@ pub use core::str::SplitWhitespace; pub use core::str::pattern; #[stable(feature = "encode_utf16", since = "1.8.0")] pub use core::str::EncodeUtf16; +#[unstable(feature = "split_ascii_whitespace", issue = "48656")] +pub use core::str::SplitAsciiWhitespace; #[unstable(feature = "slice_concat_ext", reason = "trait should not have to exist", diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 0c074582281d6..91447e01ad4fa 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -67,6 +67,8 @@ impl Layout { /// or returns `LayoutErr` if either of the following conditions /// are not met: /// + /// * `align` must not be zero, + /// /// * `align` must be a power of two, /// /// * `size`, when rounded up to the nearest multiple of `align`, diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 42fb1bc238b8e..5ae2f6349e5b7 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -21,7 +21,7 @@ use char; use fmt; use iter::{Map, Cloned, FusedIterator, TrustedLen, Filter}; use iter_private::TrustedRandomAccess; -use slice::{self, SliceIndex}; +use slice::{self, SliceIndex, Split as SliceSplit}; use mem; pub mod pattern; @@ -2722,7 +2722,10 @@ impl str { /// the original string slice, separated by any amount of whitespace. /// /// 'Whitespace' is defined according to the terms of the Unicode Derived - /// Core Property `White_Space`. + /// Core Property `White_Space`. If you only want to split on ASCII whitespace + /// instead, use [`split_ascii_whitespace`]. + /// + /// [`split_ascii_whitespace`]: #method.split_ascii_whitespace /// /// # Examples /// @@ -2756,6 +2759,53 @@ impl str { SplitWhitespace { inner: self.split(IsWhitespace).filter(IsNotEmpty) } } + /// Split a string slice by ASCII whitespace. + /// + /// The iterator returned will return string slices that are sub-slices of + /// the original string slice, separated by any amount of ASCII whitespace. + /// + /// To split by Unicode `Whitespace` instead, use [`split_whitespace`]. + /// + /// [`split_whitespace`]: #method.split_whitespace + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(split_ascii_whitespace)] + /// let mut iter = "A few words".split_ascii_whitespace(); + /// + /// assert_eq!(Some("A"), iter.next()); + /// assert_eq!(Some("few"), iter.next()); + /// assert_eq!(Some("words"), iter.next()); + /// + /// assert_eq!(None, iter.next()); + /// ``` + /// + /// All kinds of ASCII whitespace are considered: + /// + /// ``` + /// let mut iter = " Mary had\ta little \n\t lamb".split_whitespace(); + /// assert_eq!(Some("Mary"), iter.next()); + /// assert_eq!(Some("had"), iter.next()); + /// assert_eq!(Some("a"), iter.next()); + /// assert_eq!(Some("little"), iter.next()); + /// assert_eq!(Some("lamb"), iter.next()); + /// + /// assert_eq!(None, iter.next()); + /// ``` + #[unstable(feature = "split_ascii_whitespace", issue = "48656")] + #[inline] + pub fn split_ascii_whitespace(&self) -> SplitAsciiWhitespace { + let inner = self + .as_bytes() + .split(IsAsciiWhitespace) + .filter(IsNotEmpty) + .map(UnsafeBytesToStr); + SplitAsciiWhitespace { inner } + } + /// An iterator over the lines of a string, as string slices. /// /// Lines are ended with either a newline (`\n`) or a carriage return with @@ -3895,6 +3945,20 @@ pub struct SplitWhitespace<'a> { inner: Filter, IsNotEmpty>, } +/// An iterator over the non-ASCII-whitespace substrings of a string, +/// separated by any amount of ASCII whitespace. +/// +/// This struct is created by the [`split_ascii_whitespace`] method on [`str`]. +/// See its documentation for more. +/// +/// [`split_ascii_whitespace`]: ../../std/primitive.str.html#method.split_ascii_whitespace +/// [`str`]: ../../std/primitive.str.html +#[unstable(feature = "split_ascii_whitespace", issue = "48656")] +#[derive(Clone, Debug)] +pub struct SplitAsciiWhitespace<'a> { + inner: Map, IsNotEmpty>, UnsafeBytesToStr>, +} + #[derive(Clone)] struct IsWhitespace; @@ -3914,6 +3978,25 @@ impl FnMut<(char, )> for IsWhitespace { } } +#[derive(Clone)] +struct IsAsciiWhitespace; + +impl<'a> FnOnce<(&'a u8, )> for IsAsciiWhitespace { + type Output = bool; + + #[inline] + extern "rust-call" fn call_once(mut self, arg: (&u8, )) -> bool { + self.call_mut(arg) + } +} + +impl<'a> FnMut<(&'a u8, )> for IsAsciiWhitespace { + #[inline] + extern "rust-call" fn call_mut(&mut self, arg: (&u8, )) -> bool { + arg.0.is_ascii_whitespace() + } +} + #[derive(Clone)] struct IsNotEmpty; @@ -3921,30 +4004,72 @@ impl<'a, 'b> FnOnce<(&'a &'b str, )> for IsNotEmpty { type Output = bool; #[inline] - extern "rust-call" fn call_once(mut self, arg: (&&str, )) -> bool { + extern "rust-call" fn call_once(mut self, arg: (&'a &'b str, )) -> bool { self.call_mut(arg) } } impl<'a, 'b> FnMut<(&'a &'b str, )> for IsNotEmpty { #[inline] - extern "rust-call" fn call_mut(&mut self, arg: (&&str, )) -> bool { + extern "rust-call" fn call_mut(&mut self, arg: (&'a &'b str, )) -> bool { + !arg.0.is_empty() + } +} + +impl<'a, 'b> FnOnce<(&'a &'b [u8], )> for IsNotEmpty { + type Output = bool; + + #[inline] + extern "rust-call" fn call_once(mut self, arg: (&'a &'b [u8], )) -> bool { + self.call_mut(arg) + } +} + +impl<'a, 'b> FnMut<(&'a &'b [u8], )> for IsNotEmpty { + #[inline] + extern "rust-call" fn call_mut(&mut self, arg: (&'a &'b [u8], )) -> bool { !arg.0.is_empty() } } +#[derive(Clone)] +struct UnsafeBytesToStr; + +impl<'a> FnOnce<(&'a [u8], )> for UnsafeBytesToStr { + type Output = &'a str; + + #[inline] + extern "rust-call" fn call_once(mut self, arg: (&'a [u8], )) -> &'a str { + self.call_mut(arg) + } +} + +impl<'a> FnMut<(&'a [u8], )> for UnsafeBytesToStr { + #[inline] + extern "rust-call" fn call_mut(&mut self, arg: (&'a [u8], )) -> &'a str { + unsafe { from_utf8_unchecked(arg.0) } + } +} + #[stable(feature = "split_whitespace", since = "1.1.0")] impl<'a> Iterator for SplitWhitespace<'a> { type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { self.inner.next() } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } } #[stable(feature = "split_whitespace", since = "1.1.0")] impl<'a> DoubleEndedIterator for SplitWhitespace<'a> { + #[inline] fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() } @@ -3953,6 +4078,32 @@ impl<'a> DoubleEndedIterator for SplitWhitespace<'a> { #[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for SplitWhitespace<'a> {} +#[unstable(feature = "split_ascii_whitespace", issue = "48656")] +impl<'a> Iterator for SplitAsciiWhitespace<'a> { + type Item = &'a str; + + #[inline] + fn next(&mut self) -> Option<&'a str> { + self.inner.next() + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } +} + +#[unstable(feature = "split_ascii_whitespace", issue = "48656")] +impl<'a> DoubleEndedIterator for SplitAsciiWhitespace<'a> { + #[inline] + fn next_back(&mut self) -> Option<&'a str> { + self.inner.next_back() + } +} + +#[unstable(feature = "split_ascii_whitespace", issue = "48656")] +impl<'a> FusedIterator for SplitAsciiWhitespace<'a> {} + /// An iterator of [`u16`] over the string encoded as UTF-16. /// /// [`u16`]: ../../std/primitive.u16.html diff --git a/src/libcore/tests/num/mod.rs b/src/libcore/tests/num/mod.rs index b5e6a019a228c..24fe96a2b8255 100644 --- a/src/libcore/tests/num/mod.rs +++ b/src/libcore/tests/num/mod.rs @@ -574,6 +574,25 @@ macro_rules! test_float { assert_eq!((-9.0 as $fty).max($nan), -9.0); assert!(($nan as $fty).max($nan).is_nan()); } + #[test] + fn mod_euc() { + let a: $fty = 42.0; + assert!($inf.mod_euc(a).is_nan()); + assert_eq!(a.mod_euc($inf), a); + assert!(a.mod_euc($nan).is_nan()); + assert!($inf.mod_euc($inf).is_nan()); + assert!($inf.mod_euc($nan).is_nan()); + assert!($nan.mod_euc($inf).is_nan()); + } + #[test] + fn div_euc() { + let a: $fty = 42.0; + assert_eq!(a.div_euc($inf), 0.0); + assert!(a.div_euc($nan).is_nan()); + assert!($inf.div_euc($inf).is_nan()); + assert!($inf.div_euc($nan).is_nan()); + assert!($nan.div_euc($inf).is_nan()); + } } } } diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index d0ae0bdac8c09..6d2df4c201813 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -124,10 +124,10 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx let concrete_ty = generic_ty.subst(self.tcx(), substs); self.anon_depth += 1; if concrete_ty == ty { - println!("generic_ty: {:#?}", generic_ty); - println!("substs {:#?}", substs); + bug!("infinite recursion generic_ty: {:#?}, substs: {:#?}, \ + concrete_ty: {:#?}, ty: {:#?}", generic_ty, substs, concrete_ty, + ty); } - assert_ne!(concrete_ty, ty, "infinite recursion"); let folded_ty = self.fold_ty(concrete_ty); self.anon_depth -= 1; folded_ty diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index ae30321f46dfc..8e8340b3ed901 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -254,7 +254,14 @@ impl f32 { /// Calculates the Euclidean modulo (self mod rhs), which is never negative. /// - /// In particular, the result `n` satisfies `0 <= n < rhs.abs()`. + /// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in + /// most cases. However, due to a floating point round-off error it can + /// result in `r == rhs.abs()`, violating the mathematical definition, if + /// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`. + /// This result is not an element of the function's codomain, but it is the + /// closest floating point number in the real numbers and thus fulfills the + /// property `self == self.div_euc(rhs) * rhs + self.mod_euc(rhs)` + /// approximatively. /// /// # Examples /// @@ -266,6 +273,8 @@ impl f32 { /// assert_eq!((-a).mod_euc(b), 1.0); /// assert_eq!(a.mod_euc(-b), 3.0); /// assert_eq!((-a).mod_euc(-b), 1.0); + /// // limitation due to round-off error + /// assert!((-std::f32::EPSILON).mod_euc(3.0) != 0.0); /// ``` #[inline] #[unstable(feature = "euclidean_division", issue = "49048")] diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 7950d434b77e6..6880294afcaaf 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -230,7 +230,14 @@ impl f64 { /// Calculates the Euclidean modulo (self mod rhs), which is never negative. /// - /// In particular, the result `n` satisfies `0 <= n < rhs.abs()`. + /// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in + /// most cases. However, due to a floating point round-off error it can + /// result in `r == rhs.abs()`, violating the mathematical definition, if + /// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`. + /// This result is not an element of the function's codomain, but it is the + /// closest floating point number in the real numbers and thus fulfills the + /// property `self == self.div_euc(rhs) * rhs + self.mod_euc(rhs)` + /// approximatively. /// /// # Examples /// @@ -242,6 +249,8 @@ impl f64 { /// assert_eq!((-a).mod_euc(b), 1.0); /// assert_eq!(a.mod_euc(-b), 3.0); /// assert_eq!((-a).mod_euc(-b), 1.0); + /// // limitation due to round-off error + /// assert!((-std::f64::EPSILON).mod_euc(3.0) != 0.0); /// ``` #[inline] #[unstable(feature = "euclidean_division", issue = "49048")] diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 40d3280baa687..a170abb2628e5 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -276,7 +276,7 @@ impl LocalKey { /// /// This will lazily initialize the value if this thread has not referenced /// this key yet. If the key has been destroyed (which may happen if this is called - /// in a destructor), this function will return a `ThreadLocalError`. + /// in a destructor), this function will return an [`AccessError`](struct.AccessError.html). /// /// # Panics /// diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index c813ec1977b88..6d55b3de75d2e 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1359,17 +1359,17 @@ pub const EXPLAIN_LITERAL_MATCHER: &'static str = ":literal fragment specifier is experimental and subject to change"; pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &'static str = - "Unsized tuple coercion is not stable enough for use and is subject to change"; + "unsized tuple coercion is not stable enough for use and is subject to change"; pub const EXPLAIN_MACRO_AT_MOST_ONCE_REP: &'static str = - "Using the `?` macro Kleene operator for \"at most one\" repetition is unstable"; + "using the `?` macro Kleene operator for \"at most one\" repetition is unstable"; pub const EXPLAIN_MACROS_IN_EXTERN: &'static str = - "Macro invocations in `extern {}` blocks are experimental."; + "macro invocations in `extern {}` blocks are experimental."; // mention proc-macros when enabled pub const EXPLAIN_PROC_MACROS_IN_EXTERN: &'static str = - "Macro and proc-macro invocations in `extern {}` blocks are experimental."; + "macro and proc-macro invocations in `extern {}` blocks are experimental."; struct PostExpansionVisitor<'a> { context: &'a Context<'a>, diff --git a/src/test/compile-fail-fulldeps/proc-macro/macros-in-extern.rs b/src/test/compile-fail-fulldeps/proc-macro/macros-in-extern.rs index 4c88df332460b..75d5ac6495ae8 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/macros-in-extern.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/macros-in-extern.rs @@ -26,13 +26,13 @@ fn main() { #[link(name = "rust_test_helpers", kind = "static")] extern { #[no_output] - //~^ ERROR Macro and proc-macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro and proc-macro invocations in `extern {}` blocks are experimental. fn some_definitely_unknown_symbol_which_should_be_removed(); #[nop_attr] - //~^ ERROR Macro and proc-macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro and proc-macro invocations in `extern {}` blocks are experimental. fn rust_get_test_int() -> isize; emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); - //~^ ERROR Macro and proc-macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro and proc-macro invocations in `extern {}` blocks are experimental. } diff --git a/src/test/compile-fail/edition-raw-pointer-method-2015.rs b/src/test/compile-fail/edition-raw-pointer-method-2015.rs index b304443f63145..4ba44fa54d8cd 100644 --- a/src/test/compile-fail/edition-raw-pointer-method-2015.rs +++ b/src/test/compile-fail/edition-raw-pointer-method-2015.rs @@ -9,7 +9,7 @@ // except according to those terms. // ignore-tidy-linelength -// compile-flags: --edition=2015 -Zunstable-options +// edition:2015 // tests that editions work with the tyvar warning-turned-error diff --git a/src/test/compile-fail/edition-raw-pointer-method-2018.rs b/src/test/compile-fail/edition-raw-pointer-method-2018.rs index d0cf81d59cf37..c8548ed35b972 100644 --- a/src/test/compile-fail/edition-raw-pointer-method-2018.rs +++ b/src/test/compile-fail/edition-raw-pointer-method-2018.rs @@ -9,7 +9,7 @@ // except according to those terms. // ignore-tidy-linelength -// compile-flags: --edition=2018 -Zunstable-options +// edition:2018 // tests that editions work with the tyvar warning-turned-error diff --git a/src/test/compile-fail/macros-in-extern.rs b/src/test/compile-fail/macros-in-extern.rs index 7d7f95cbbf5cb..b6e273881ccd6 100644 --- a/src/test/compile-fail/macros-in-extern.rs +++ b/src/test/compile-fail/macros-in-extern.rs @@ -34,9 +34,9 @@ fn main() { #[link(name = "rust_test_helpers", kind = "static")] extern { returns_isize!(rust_get_test_int); - //~^ ERROR Macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro invocations in `extern {}` blocks are experimental. takes_u32_returns_u32!(rust_dbg_extern_identity_u32); - //~^ ERROR Macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro invocations in `extern {}` blocks are experimental. emits_nothing!(); - //~^ ERROR Macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro invocations in `extern {}` blocks are experimental. } diff --git a/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-1.rs b/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-1.rs index fcf4714ba9695..e04bb27f43500 100644 --- a/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-1.rs +++ b/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-1.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 -Zunstable-options +// edition:2018 #![feature(extern_absolute_paths)] diff --git a/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-2.rs b/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-2.rs index c256c5592c269..bebf0236bb4d0 100644 --- a/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-2.rs +++ b/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 -Zunstable-options +// edition:2018 #![feature(extern_absolute_paths)] diff --git a/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-3.rs b/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-3.rs index 837dc617b3ad0..5906a0719c842 100644 --- a/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-3.rs +++ b/src/test/compile-fail/rfc-2126-extern-absolute-paths/non-existent-3.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 -Zunstable-options +// edition:2018 #![feature(extern_absolute_paths)] diff --git a/src/test/compile-fail/rfc-2126-extern-absolute-paths/single-segment.rs b/src/test/compile-fail/rfc-2126-extern-absolute-paths/single-segment.rs index 9b7baa0016344..7111176dbd9af 100644 --- a/src/test/compile-fail/rfc-2126-extern-absolute-paths/single-segment.rs +++ b/src/test/compile-fail/rfc-2126-extern-absolute-paths/single-segment.rs @@ -9,7 +9,7 @@ // except according to those terms. // aux-build:xcrate.rs -// compile-flags: --edition=2018 -Zunstable-options +// edition:2018 #![feature(crate_in_paths)] #![feature(extern_absolute_paths)] diff --git a/src/test/run-pass/async-await.rs b/src/test/run-pass/async-await.rs index 817db4bb79ec3..8b649f6ef7bbd 100644 --- a/src/test/run-pass/async-await.rs +++ b/src/test/run-pass/async-await.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 #![feature(arbitrary_self_types, async_await, await_macro, futures_api, pin)] diff --git a/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs b/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs index 9127c8e350a8c..69952e9f90af6 100644 --- a/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 #![feature(raw_identifiers)] diff --git a/src/test/run-pass/auxiliary/edition-kw-macro-2018.rs b/src/test/run-pass/auxiliary/edition-kw-macro-2018.rs index 4fef77d67ea71..415988586a066 100644 --- a/src/test/run-pass/auxiliary/edition-kw-macro-2018.rs +++ b/src/test/run-pass/auxiliary/edition-kw-macro-2018.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 #![feature(raw_identifiers)] diff --git a/src/test/run-pass/edition-keywords-2015-2015.rs b/src/test/run-pass/edition-keywords-2015-2015.rs index 41480bb978ec2..73869e63de7c4 100644 --- a/src/test/run-pass/edition-keywords-2015-2015.rs +++ b/src/test/run-pass/edition-keywords-2015-2015.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 // aux-build:edition-kw-macro-2015.rs #![feature(raw_identifiers)] diff --git a/src/test/run-pass/edition-keywords-2015-2018.rs b/src/test/run-pass/edition-keywords-2015-2018.rs index 78835d510639f..0a1c6505854c9 100644 --- a/src/test/run-pass/edition-keywords-2015-2018.rs +++ b/src/test/run-pass/edition-keywords-2015-2018.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 // aux-build:edition-kw-macro-2018.rs #![feature(raw_identifiers)] diff --git a/src/test/run-pass/edition-keywords-2018-2015.rs b/src/test/run-pass/edition-keywords-2018-2015.rs index 46d5f222cbb31..4c22667d0bf43 100644 --- a/src/test/run-pass/edition-keywords-2018-2015.rs +++ b/src/test/run-pass/edition-keywords-2018-2015.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 // aux-build:edition-kw-macro-2015.rs #![feature(raw_identifiers)] diff --git a/src/test/run-pass/edition-keywords-2018-2018.rs b/src/test/run-pass/edition-keywords-2018-2018.rs index 06482988937b6..2a98b904da5db 100644 --- a/src/test/run-pass/edition-keywords-2018-2018.rs +++ b/src/test/run-pass/edition-keywords-2018-2018.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 // aux-build:edition-kw-macro-2018.rs #![feature(raw_identifiers)] diff --git a/src/test/run-pass/rfc-2126-extern-absolute-paths/basic.rs b/src/test/run-pass/rfc-2126-extern-absolute-paths/basic.rs index bbe066481a8b1..dfa583415f7b6 100644 --- a/src/test/run-pass/rfc-2126-extern-absolute-paths/basic.rs +++ b/src/test/run-pass/rfc-2126-extern-absolute-paths/basic.rs @@ -9,7 +9,7 @@ // except according to those terms. // aux-build:xcrate.rs -// compile-flags: --edition=2018 -Zunstable-options +// edition:2018 #![feature(extern_absolute_paths)] diff --git a/src/test/run-pass/rfc-2126-extern-absolute-paths/test.rs b/src/test/run-pass/rfc-2126-extern-absolute-paths/test.rs index ead462cf0d2ca..6317dc17652cd 100644 --- a/src/test/run-pass/rfc-2126-extern-absolute-paths/test.rs +++ b/src/test/run-pass/rfc-2126-extern-absolute-paths/test.rs @@ -12,7 +12,8 @@ // // Regression test for #47075. -// compile-flags: --test --edition=2018 -Zunstable-options +// edition:2018 +// compile-flags: --test #![feature(extern_absolute_paths)] diff --git a/src/test/ui/async-fn-multiple-lifetimes.rs b/src/test/ui/async-fn-multiple-lifetimes.rs index ce062ded7f73f..aab4974e2e7a1 100644 --- a/src/test/ui/async-fn-multiple-lifetimes.rs +++ b/src/test/ui/async-fn-multiple-lifetimes.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 #![feature(arbitrary_self_types, async_await, await_macro, futures_api, pin)] diff --git a/src/test/ui/auxiliary/edition-kw-macro-2015.rs b/src/test/ui/auxiliary/edition-kw-macro-2015.rs index 9127c8e350a8c..69952e9f90af6 100644 --- a/src/test/ui/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/ui/auxiliary/edition-kw-macro-2015.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 #![feature(raw_identifiers)] diff --git a/src/test/ui/auxiliary/edition-kw-macro-2018.rs b/src/test/ui/auxiliary/edition-kw-macro-2018.rs index 4fef77d67ea71..415988586a066 100644 --- a/src/test/ui/auxiliary/edition-kw-macro-2018.rs +++ b/src/test/ui/auxiliary/edition-kw-macro-2018.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 #![feature(raw_identifiers)] diff --git a/src/test/ui/edition-keywords-2015-2015-expansion.rs b/src/test/ui/edition-keywords-2015-2015-expansion.rs index b8a1994a10575..349ab3e27ad32 100644 --- a/src/test/ui/edition-keywords-2015-2015-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2015-expansion.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 // aux-build:edition-kw-macro-2015.rs // compile-pass diff --git a/src/test/ui/edition-keywords-2015-2015-parsing.rs b/src/test/ui/edition-keywords-2015-2015-parsing.rs index 1fb91ca006cc7..08cba2d2908a6 100644 --- a/src/test/ui/edition-keywords-2015-2015-parsing.rs +++ b/src/test/ui/edition-keywords-2015-2015-parsing.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 // aux-build:edition-kw-macro-2015.rs #![feature(raw_identifiers)] diff --git a/src/test/ui/edition-keywords-2015-2018-expansion.rs b/src/test/ui/edition-keywords-2015-2018-expansion.rs index bc14c104c49fc..082eb8d89f9f1 100644 --- a/src/test/ui/edition-keywords-2015-2018-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2018-expansion.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 // aux-build:edition-kw-macro-2018.rs #![feature(raw_identifiers)] diff --git a/src/test/ui/edition-keywords-2015-2018-parsing.rs b/src/test/ui/edition-keywords-2015-2018-parsing.rs index 0b680eb16c7f4..337d6be6bbcd8 100644 --- a/src/test/ui/edition-keywords-2015-2018-parsing.rs +++ b/src/test/ui/edition-keywords-2015-2018-parsing.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 // aux-build:edition-kw-macro-2018.rs #![feature(raw_identifiers)] diff --git a/src/test/ui/edition-keywords-2018-2015-expansion.rs b/src/test/ui/edition-keywords-2018-2015-expansion.rs index 6f85f427eb054..6e2073e0e494a 100644 --- a/src/test/ui/edition-keywords-2018-2015-expansion.rs +++ b/src/test/ui/edition-keywords-2018-2015-expansion.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 // aux-build:edition-kw-macro-2015.rs // compile-pass diff --git a/src/test/ui/edition-keywords-2018-2015-parsing.rs b/src/test/ui/edition-keywords-2018-2015-parsing.rs index 02dc8c8795675..713da57f7e2c7 100644 --- a/src/test/ui/edition-keywords-2018-2015-parsing.rs +++ b/src/test/ui/edition-keywords-2018-2015-parsing.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 // aux-build:edition-kw-macro-2015.rs #![feature(raw_identifiers)] diff --git a/src/test/ui/edition-keywords-2018-2018-expansion.rs b/src/test/ui/edition-keywords-2018-2018-expansion.rs index ef7f63e225ce1..50db4202e98d3 100644 --- a/src/test/ui/edition-keywords-2018-2018-expansion.rs +++ b/src/test/ui/edition-keywords-2018-2018-expansion.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 // aux-build:edition-kw-macro-2018.rs #![feature(raw_identifiers)] diff --git a/src/test/ui/edition-keywords-2018-2018-parsing.rs b/src/test/ui/edition-keywords-2018-2018-parsing.rs index f9b4d0e18c14b..263ec95caa7d6 100644 --- a/src/test/ui/edition-keywords-2018-2018-parsing.rs +++ b/src/test/ui/edition-keywords-2018-2018-parsing.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 // aux-build:edition-kw-macro-2018.rs #![feature(raw_identifiers)] diff --git a/src/test/ui/feature-gate-async-await-2015-edition.rs b/src/test/ui/feature-gate-async-await-2015-edition.rs index b1dd6a77e976a..5b865e9c1c7cb 100644 --- a/src/test/ui/feature-gate-async-await-2015-edition.rs +++ b/src/test/ui/feature-gate-async-await-2015-edition.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2015 +// edition:2015 #![feature(futures_api)] diff --git a/src/test/ui/feature-gate-async-await.rs b/src/test/ui/feature-gate-async-await.rs index 971b75c6dd036..be34842dea3a6 100644 --- a/src/test/ui/feature-gate-async-await.rs +++ b/src/test/ui/feature-gate-async-await.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 + #![feature(futures_api)] async fn foo() {} //~ ERROR async fn is unstable diff --git a/src/test/ui/feature-gate-async-await.stderr b/src/test/ui/feature-gate-async-await.stderr index fdee6e205750b..79ed5c4d008b1 100644 --- a/src/test/ui/feature-gate-async-await.stderr +++ b/src/test/ui/feature-gate-async-await.stderr @@ -1,5 +1,5 @@ error[E0658]: async fn is unstable (see issue #50547) - --> $DIR/feature-gate-async-await.rs:14:1 + --> $DIR/feature-gate-async-await.rs:15:1 | LL | async fn foo() {} //~ ERROR async fn is unstable | ^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | async fn foo() {} //~ ERROR async fn is unstable = help: add #![feature(async_await)] to the crate attributes to enable error[E0658]: async blocks are unstable (see issue #50547) - --> $DIR/feature-gate-async-await.rs:17:13 + --> $DIR/feature-gate-async-await.rs:18:13 | LL | let _ = async {}; //~ ERROR async blocks are unstable | ^^^^^^^^ @@ -15,7 +15,7 @@ LL | let _ = async {}; //~ ERROR async blocks are unstable = help: add #![feature(async_await)] to the crate attributes to enable error[E0658]: async closures are unstable (see issue #50547) - --> $DIR/feature-gate-async-await.rs:18:13 + --> $DIR/feature-gate-async-await.rs:19:13 | LL | let _ = async || {}; //~ ERROR async closures are unstable | ^^^^^^^^^^^ diff --git a/src/test/ui/feature-gate-macro_at_most_once_rep.rs b/src/test/ui/feature-gate-macro_at_most_once_rep.rs index 19f5aca5730e1..bdce1952a9a21 100644 --- a/src/test/ui/feature-gate-macro_at_most_once_rep.rs +++ b/src/test/ui/feature-gate-macro_at_most_once_rep.rs @@ -12,7 +12,7 @@ // gate is not used. macro_rules! m { ($(a)?) => {} } -//~^ ERROR Using the `?` macro Kleene operator for "at most one" repetition is unstable +//~^ ERROR using the `?` macro Kleene operator for "at most one" repetition is unstable fn main() { m!(); diff --git a/src/test/ui/feature-gate-macro_at_most_once_rep.stderr b/src/test/ui/feature-gate-macro_at_most_once_rep.stderr index 8eba07e6c088b..9ca71d937f859 100644 --- a/src/test/ui/feature-gate-macro_at_most_once_rep.stderr +++ b/src/test/ui/feature-gate-macro_at_most_once_rep.stderr @@ -1,4 +1,4 @@ -error[E0658]: Using the `?` macro Kleene operator for "at most one" repetition is unstable (see issue #48075) +error[E0658]: using the `?` macro Kleene operator for "at most one" repetition is unstable (see issue #48075) --> $DIR/feature-gate-macro_at_most_once_rep.rs:14:20 | LL | macro_rules! m { ($(a)?) => {} } diff --git a/src/test/ui/feature-gate-macros_in_extern.rs b/src/test/ui/feature-gate-macros_in_extern.rs index 9c758241ea1b8..5271f75b6328c 100644 --- a/src/test/ui/feature-gate-macros_in_extern.rs +++ b/src/test/ui/feature-gate-macros_in_extern.rs @@ -27,9 +27,9 @@ macro_rules! emits_nothing( #[link(name = "rust_test_helpers", kind = "static")] extern { returns_isize!(rust_get_test_int); - //~^ ERROR Macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro invocations in `extern {}` blocks are experimental. takes_u32_returns_u32!(rust_dbg_extern_identity_u32); - //~^ ERROR Macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro invocations in `extern {}` blocks are experimental. emits_nothing!(); - //~^ ERROR Macro invocations in `extern {}` blocks are experimental. + //~^ ERROR macro invocations in `extern {}` blocks are experimental. } diff --git a/src/test/ui/feature-gate-macros_in_extern.stderr b/src/test/ui/feature-gate-macros_in_extern.stderr index 49aca0db2d46c..748adc390d8bb 100644 --- a/src/test/ui/feature-gate-macros_in_extern.stderr +++ b/src/test/ui/feature-gate-macros_in_extern.stderr @@ -1,4 +1,4 @@ -error[E0658]: Macro invocations in `extern {}` blocks are experimental. (see issue #49476) +error[E0658]: macro invocations in `extern {}` blocks are experimental. (see issue #49476) --> $DIR/feature-gate-macros_in_extern.rs:29:5 | LL | returns_isize!(rust_get_test_int); @@ -6,7 +6,7 @@ LL | returns_isize!(rust_get_test_int); | = help: add #![feature(macros_in_extern)] to the crate attributes to enable -error[E0658]: Macro invocations in `extern {}` blocks are experimental. (see issue #49476) +error[E0658]: macro invocations in `extern {}` blocks are experimental. (see issue #49476) --> $DIR/feature-gate-macros_in_extern.rs:31:5 | LL | takes_u32_returns_u32!(rust_dbg_extern_identity_u32); @@ -14,7 +14,7 @@ LL | takes_u32_returns_u32!(rust_dbg_extern_identity_u32); | = help: add #![feature(macros_in_extern)] to the crate attributes to enable -error[E0658]: Macro invocations in `extern {}` blocks are experimental. (see issue #49476) +error[E0658]: macro invocations in `extern {}` blocks are experimental. (see issue #49476) --> $DIR/feature-gate-macros_in_extern.rs:33:5 | LL | emits_nothing!(); diff --git a/src/test/ui/feature-gate-unsized_tuple_coercion.rs b/src/test/ui/feature-gate-unsized_tuple_coercion.rs index 4ddde01126363..8a43e75494d81 100644 --- a/src/test/ui/feature-gate-unsized_tuple_coercion.rs +++ b/src/test/ui/feature-gate-unsized_tuple_coercion.rs @@ -10,5 +10,5 @@ fn main() { let _ : &(Send,) = &((),); - //~^ ERROR Unsized tuple coercion is not stable enough + //~^ ERROR unsized tuple coercion is not stable enough } diff --git a/src/test/ui/feature-gate-unsized_tuple_coercion.stderr b/src/test/ui/feature-gate-unsized_tuple_coercion.stderr index bf790a3b00390..08c15855a6a42 100644 --- a/src/test/ui/feature-gate-unsized_tuple_coercion.stderr +++ b/src/test/ui/feature-gate-unsized_tuple_coercion.stderr @@ -1,4 +1,4 @@ -error[E0658]: Unsized tuple coercion is not stable enough for use and is subject to change (see issue #42877) +error[E0658]: unsized tuple coercion is not stable enough for use and is subject to change (see issue #42877) --> $DIR/feature-gate-unsized_tuple_coercion.rs:12:24 | LL | let _ : &(Send,) = &((),); diff --git a/src/test/ui/lint-anon-param-edition.fixed b/src/test/ui/lint-anon-param-edition.fixed index de223d9ccf7b6..c4379b496f8d4 100644 --- a/src/test/ui/lint-anon-param-edition.fixed +++ b/src/test/ui/lint-anon-param-edition.fixed @@ -11,7 +11,7 @@ // tests that the anonymous_parameters lint is warn-by-default on the 2018 edition // compile-pass -// compile-flags: --edition=2018 +// edition:2018 // run-rustfix trait Foo { diff --git a/src/test/ui/lint-anon-param-edition.rs b/src/test/ui/lint-anon-param-edition.rs index 35406806df99c..13eb5dfd816ab 100644 --- a/src/test/ui/lint-anon-param-edition.rs +++ b/src/test/ui/lint-anon-param-edition.rs @@ -11,7 +11,7 @@ // tests that the anonymous_parameters lint is warn-by-default on the 2018 edition // compile-pass -// compile-flags: --edition=2018 +// edition:2018 // run-rustfix trait Foo { diff --git a/src/test/ui/no-args-non-move-async-closure.rs b/src/test/ui/no-args-non-move-async-closure.rs index f2ecc44771883..9cb754167cfe5 100644 --- a/src/test/ui/no-args-non-move-async-closure.rs +++ b/src/test/ui/no-args-non-move-async-closure.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --edition=2018 +// edition:2018 #![feature(arbitrary_self_types, async_await, await_macro, futures_api, pin)] diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index f66f5c5b70e7e..1dd7fe7f0cb39 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -298,6 +298,10 @@ impl TestProps { .extend(flags.split_whitespace().map(|s| s.to_owned())); } + if let Some(edition) = config.parse_edition(ln) { + self.compile_flags.push(format!("--edition={}", edition)); + } + if let Some(r) = config.parse_revisions(ln) { self.revisions.extend(r); } @@ -371,9 +375,9 @@ impl TestProps { self.compile_pass = config.parse_compile_pass(ln) || self.run_pass; } - if !self.skip_codegen { - self.skip_codegen = config.parse_skip_codegen(ln); - } + if !self.skip_codegen { + self.skip_codegen = config.parse_skip_codegen(ln); + } if !self.disable_ui_testing_normalization { self.disable_ui_testing_normalization = @@ -647,6 +651,10 @@ impl Config { fn parse_run_rustfix(&self, line: &str) -> bool { self.parse_name_directive(line, "run-rustfix") } + + fn parse_edition(&self, line: &str) -> Option { + self.parse_name_value_directive(line, "edition") + } } pub fn lldb_version_to_int(version_string: &str) -> isize { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index caf73f4f68b03..408eda5ba5bb5 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1368,6 +1368,7 @@ impl<'test> TestCx<'test> { .arg(out_dir) .arg(&self.testpaths.file) .args(&self.props.compile_flags); + if let Some(ref linker) = self.config.linker { rustdoc .arg("--linker")