From 5d1f100988c12dabf5a34854e9db6875b999e357 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Sat, 23 Feb 2019 21:07:04 -0500 Subject: [PATCH 01/12] Add unstable option to ignore should_panic tests. --- src/libtest/lib.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 5c7fb1b804461..a712d4092308b 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -366,6 +366,7 @@ pub struct TestOpts { pub list: bool, pub filter: Option, pub filter_exact: bool, + pub exclude_should_panic: bool, pub run_ignored: RunIgnored, pub run_tests: bool, pub bench_benchmarks: bool, @@ -385,6 +386,7 @@ impl TestOpts { list: false, filter: None, filter_exact: false, + exclude_should_panic: false, run_ignored: RunIgnored::No, run_tests: false, bench_benchmarks: false, @@ -406,6 +408,7 @@ fn optgroups() -> getopts::Options { let mut opts = getopts::Options::new(); opts.optflag("", "include-ignored", "Run ignored and not ignored tests") .optflag("", "ignored", "Run only ignored tests") + .optflag("", "exclude-should-panic", "Sets #[should_panic] tests to imply #[ignore]") .optflag("", "test", "Run tests and not benchmarks") .optflag("", "bench", "Run benchmarks instead of tests") .optflag("", "list", "List all tests and benchmarks") @@ -558,6 +561,13 @@ pub fn parse_opts(args: &[String]) -> Option { None }; + let exclude_should_panic = matches.opt_present("exclude-should-panic"); + if !allow_unstable && exclude_should_panic { + return Some(Err( + "The \"exclude-should-panic\" flag is only accepted on the nightly compiler".into(), + )); + } + let include_ignored = matches.opt_present("include-ignored"); if !allow_unstable && include_ignored { return Some(Err( @@ -648,6 +658,7 @@ pub fn parse_opts(args: &[String]) -> Option { list, filter, filter_exact: exact, + exclude_should_panic, run_ignored, run_tests, bench_benchmarks, @@ -1365,6 +1376,14 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec) -> Vec { @@ -1983,6 +2002,32 @@ mod tests { assert!(!filtered[1].desc.ignore); } + #[test] + pub fn exclude_should_panic_option() { + let mut opts = TestOpts::new(); + opts.run_tests = true; + opts.exclude_should_panic = true; + + let mut tests = one_ignored_one_unignored_test(); + + tests.push(TestDescAndFn { + desc: TestDesc { + name: StaticTestName("3"), + ignore: false, + should_panic: ShouldPanic::YesWithMessage("should panic with message"), + allow_fail: false, + }, + testfn: DynTestFn(Box::new(move || {})), + }); + + let filtered = filter_tests(&opts, tests); + + assert_eq!(filtered.len(), 3); + assert!(filtered[0].desc.ignore); + assert!(!filtered[1].desc.ignore); + assert!(filtered[2].desc.ignore); + } + #[test] pub fn exact_filter_match() { fn tests() -> Vec { From 43e7434120a10f86713091667258f58b6c245e2d Mon Sep 17 00:00:00 2001 From: memoryruins Date: Sun, 24 Feb 2019 11:58:08 -0500 Subject: [PATCH 02/12] Simplify exclude_should_panic flag. --- src/libtest/lib.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index a712d4092308b..ea821a1d9392c 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -408,7 +408,7 @@ fn optgroups() -> getopts::Options { let mut opts = getopts::Options::new(); opts.optflag("", "include-ignored", "Run ignored and not ignored tests") .optflag("", "ignored", "Run only ignored tests") - .optflag("", "exclude-should-panic", "Sets #[should_panic] tests to imply #[ignore]") + .optflag("", "exclude-should-panic", "Excludes tests marked as should_panic") .optflag("", "test", "Run tests and not benchmarks") .optflag("", "bench", "Run benchmarks instead of tests") .optflag("", "list", "List all tests and benchmarks") @@ -1376,12 +1376,9 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec) -> Vec Date: Mon, 25 Feb 2019 16:44:04 +0100 Subject: [PATCH 03/12] Have all methods of Filter and FilterMap use internal iteration --- src/libcore/iter/adapters/mod.rs | 37 ++++++-------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs index bca1b76dbb975..d4ad22c16bbfa 100644 --- a/src/libcore/iter/adapters/mod.rs +++ b/src/libcore/iter/adapters/mod.rs @@ -681,12 +681,7 @@ impl Iterator for Filter where P: FnMut(&I::Item) -> bool #[inline] fn next(&mut self) -> Option { - for x in &mut self.iter { - if (self.predicate)(&x) { - return Some(x); - } - } - None + self.try_for_each(Err).err() } #[inline] @@ -707,12 +702,9 @@ impl Iterator for Filter where P: FnMut(&I::Item) -> bool // Using the branchless version will also simplify the LLVM byte code, thus // leaving more budget for LLVM optimizations. #[inline] - fn count(mut self) -> usize { - let mut count = 0; - for x in &mut self.iter { - count += (self.predicate)(&x) as usize; - } - count + fn count(self) -> usize { + let mut predicate = self.predicate; + self.iter.map(|x| predicate(&x) as usize).sum() } #[inline] @@ -746,12 +738,7 @@ impl DoubleEndedIterator for Filter { #[inline] fn next_back(&mut self) -> Option { - for x in self.iter.by_ref().rev() { - if (self.predicate)(&x) { - return Some(x); - } - } - None + self.try_rfold((), |_, x| Err(x)).err() } #[inline] @@ -820,12 +807,7 @@ impl Iterator for FilterMap #[inline] fn next(&mut self) -> Option { - for x in self.iter.by_ref() { - if let Some(y) = (self.f)(x) { - return Some(y); - } - } - None + self.try_for_each(Err).err() } #[inline] @@ -863,12 +845,7 @@ impl DoubleEndedIterator for FilterMap { #[inline] fn next_back(&mut self) -> Option { - for x in self.iter.by_ref().rev() { - if let Some(y) = (self.f)(x) { - return Some(y); - } - } - None + self.try_rfold((), |_, x| Err(x)).err() } #[inline] From 88847718f0cca57124cbd1bce12fc938c5bde088 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Wed, 27 Feb 2019 11:44:30 +0100 Subject: [PATCH 04/12] Add relevant benchmarks --- src/libcore/benches/iter.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/libcore/benches/iter.rs b/src/libcore/benches/iter.rs index fe852e42b5cd3..5cc2bce846d87 100644 --- a/src/libcore/benches/iter.rs +++ b/src/libcore/benches/iter.rs @@ -306,3 +306,31 @@ fn bench_skip_then_zip(b: &mut Bencher) { assert_eq!(s, 2009900); }); } + +#[bench] +fn bench_filter_count(b: &mut Bencher) { + b.iter(|| { + (0i64..1000000).map(black_box).filter(|x| x % 3 == 0).count() + }) +} + +#[bench] +fn bench_filter_ref_count(b: &mut Bencher) { + b.iter(|| { + (0i64..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count() + }) +} + +#[bench] +fn bench_filter_chain_count(b: &mut Bencher) { + b.iter(|| { + (0i64..1000000).chain(0..1000000).map(black_box).filter(|x| x % 3 == 0).count() + }) +} + +#[bench] +fn bench_filter_chain_ref_count(b: &mut Bencher) { + b.iter(|| { + (0i64..1000000).chain(0..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count() + }) +} \ No newline at end of file From ec2e4ba919a65a972019925b5b33d0f309f467fc Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Wed, 27 Feb 2019 11:46:37 +0100 Subject: [PATCH 05/12] Improve existing benchmarks to prevent extreme optimizations --- src/libcore/benches/iter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/benches/iter.rs b/src/libcore/benches/iter.rs index 5cc2bce846d87..4f3d6f379022b 100644 --- a/src/libcore/benches/iter.rs +++ b/src/libcore/benches/iter.rs @@ -185,13 +185,13 @@ bench_sums! { bench_sums! { bench_filter_sum, bench_filter_ref_sum, - (0i64..1000000).filter(|x| x % 2 == 0) + (0i64..1000000).filter(|x| x % 3 == 0) } bench_sums! { bench_filter_chain_sum, bench_filter_chain_ref_sum, - (0i64..1000000).chain(0..1000000).filter(|x| x % 2 == 0) + (0i64..1000000).chain(0..1000000).filter(|x| x % 3 == 0) } bench_sums! { From 88bd624a88692dd4bbda5f3f324f0035dc041534 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Wed, 27 Feb 2019 13:22:18 +0100 Subject: [PATCH 06/12] Add trailing newline --- src/libcore/benches/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/benches/iter.rs b/src/libcore/benches/iter.rs index 4f3d6f379022b..1dd2bd3ee78aa 100644 --- a/src/libcore/benches/iter.rs +++ b/src/libcore/benches/iter.rs @@ -333,4 +333,4 @@ fn bench_filter_chain_ref_count(b: &mut Bencher) { b.iter(|| { (0i64..1000000).chain(0..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count() }) -} \ No newline at end of file +} From 4e7d4c7778a00371ba707fb8f9022bcbb443bb29 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 27 Feb 2019 15:32:32 +0100 Subject: [PATCH 07/12] ManuallyDrop != MaybeUninit --- src/libcore/mem.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index f41d293e80ad3..6b1b91d00faa7 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -900,10 +900,16 @@ pub fn discriminant(v: &T) -> Discriminant { } } +// FIXME: Reference `MaybeUninit` from these docs, once that is stable. /// A wrapper to inhibit compiler from automatically calling `T`’s destructor. /// /// This wrapper is 0-cost. /// +/// `ManuallyDrop` is subject to the same layout optimizations as `T`. +/// As a consequence, it has *no effect* on the assumptions that the compiler makes +/// about all values being initialized at their type. In particular, initializing +/// a `ManuallyDrop<&T>` with [`mem::zeroed`] is undefined behavior. +/// /// # Examples /// /// This wrapper helps with explicitly documenting the drop order dependencies between fields of @@ -935,6 +941,8 @@ pub fn discriminant(v: &T) -> Discriminant { /// } /// } /// ``` +/// +/// [`mem::zeroed']: fn.zeroed.html #[stable(feature = "manually_drop", since = "1.20.0")] #[lang = "manually_drop"] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] From b70a9532a9d3e2ae4b9bf7bc4a4a0bfc7dbe134b Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Wed, 20 Feb 2019 15:11:22 +0100 Subject: [PATCH 08/12] Replace `s` with `self` in docs for str methods taking self. --- src/libcore/str/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 8b51d8465141a..53334adadb856 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -3965,7 +3965,7 @@ impl str { me.make_ascii_lowercase() } - /// Return an iterator that escapes each char in `s` with [`char::escape_debug`]. + /// Return an iterator that escapes each char in `self` with [`char::escape_debug`]. /// /// Note: only extended grapheme codepoints that begin the string will be /// escaped. @@ -4013,7 +4013,7 @@ impl str { } } - /// Return an iterator that escapes each char in `s` with [`char::escape_default`]. + /// Return an iterator that escapes each char in `self` with [`char::escape_default`]. /// /// [`char::escape_default`]: ../std/primitive.char.html#method.escape_default /// @@ -4051,7 +4051,7 @@ impl str { EscapeDefault { inner: self.chars().flat_map(CharEscapeDefault) } } - /// Return an iterator that escapes each char in `s` with [`char::escape_unicode`]. + /// Return an iterator that escapes each char in `self` with [`char::escape_unicode`]. /// /// [`char::escape_unicode`]: ../std/primitive.char.html#method.escape_unicode /// From f92c20426ea5f5ddcc6dcf73dbe0739d3d76b614 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 27 Feb 2019 18:58:19 +0100 Subject: [PATCH 09/12] improve readability --- src/libcore/mem.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 6b1b91d00faa7..f78213ba9f672 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -908,7 +908,7 @@ pub fn discriminant(v: &T) -> Discriminant { /// `ManuallyDrop` is subject to the same layout optimizations as `T`. /// As a consequence, it has *no effect* on the assumptions that the compiler makes /// about all values being initialized at their type. In particular, initializing -/// a `ManuallyDrop<&T>` with [`mem::zeroed`] is undefined behavior. +/// a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined behavior. /// /// # Examples /// From a998b1f425bc13d891ed5b28f1b708970f9db4b4 Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Wed, 27 Feb 2019 10:56:58 -0500 Subject: [PATCH 10/12] allow specifying attributes for tool lints --- src/librustc/lint/mod.rs | 20 +++++++++++++------ .../ui-fulldeps/auxiliary/lint_tool_test.rs | 6 +++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index dd003e44bea09..496ff568b31b4 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -132,14 +132,22 @@ macro_rules! declare_lint { #[macro_export] macro_rules! declare_tool_lint { - ($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr) => ( - declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, false} + ( + $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr + ) => ( + declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false} ); - ($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr, - report_in_external_macro: $rep: expr) => ( - declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, $rep} + ( + $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr, + report_in_external_macro: $rep:expr + ) => ( + declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep} ); - ($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr, $external: expr) => ( + ( + $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr, + $external:expr + ) => ( + $(#[$attr])* $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { name: &concat!(stringify!($tool), "::", stringify!($NAME)), default_level: $crate::lint::$Level, diff --git a/src/test/ui-fulldeps/auxiliary/lint_tool_test.rs b/src/test/ui-fulldeps/auxiliary/lint_tool_test.rs index 1a9bd9e66dbac..d25a5ea374627 100644 --- a/src/test/ui-fulldeps/auxiliary/lint_tool_test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint_tool_test.rs @@ -13,7 +13,11 @@ use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass, use rustc_plugin::Registry; use syntax::ast; declare_tool_lint!(pub clippy::TEST_LINT, Warn, "Warn about stuff"); -declare_tool_lint!(pub clippy::TEST_GROUP, Warn, "Warn about other stuff"); +declare_tool_lint!( + /// Some docs + pub clippy::TEST_GROUP, + Warn, "Warn about other stuff" +); struct Pass; From 3aca176fb24418803f37e999ebcdb1d277b99fe4 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 27 Feb 2019 21:08:15 -0800 Subject: [PATCH 11/12] Update edition-guide --- src/bootstrap/doc.rs | 2 +- src/doc/edition-guide | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 40f0e5ede8bd7..e0ad0422a6ce3 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -60,7 +60,7 @@ macro_rules! book { // NOTE: When adding a book here, make sure to ALSO build the book by // adding a build step in `src/bootstrap/builder.rs`! book!( - EditionGuide, "src/doc/edition-guide", "edition-guide", RustbookVersion::MdBook1; + EditionGuide, "src/doc/edition-guide", "edition-guide", RustbookVersion::MdBook2; EmbeddedBook, "src/doc/embedded-book", "embedded-book", RustbookVersion::MdBook2; Nomicon, "src/doc/nomicon", "nomicon", RustbookVersion::MdBook1; Reference, "src/doc/reference", "reference", RustbookVersion::MdBook1; diff --git a/src/doc/edition-guide b/src/doc/edition-guide index 419edb885ec1a..5f3cc2a561870 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit 419edb885ec1a98c0747b3907003d79e3e6b93a9 +Subproject commit 5f3cc2a5618700efcde3bc00799744f21fa9ad2e From 0c1a38ce3b281ce23b9ba84312f58ba6ac82af57 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 28 Feb 2019 09:24:35 +0100 Subject: [PATCH 12/12] Update src/libcore/mem.rs Co-Authored-By: RalfJung --- src/libcore/mem.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index f78213ba9f672..94f342e7e8efc 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -942,7 +942,7 @@ pub fn discriminant(v: &T) -> Discriminant { /// } /// ``` /// -/// [`mem::zeroed']: fn.zeroed.html +/// [`mem::zeroed`]: fn.zeroed.html #[stable(feature = "manually_drop", since = "1.20.0")] #[lang = "manually_drop"] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]