From 347ed001e81607f609f7c47a6d7cd5f723c288a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Mon, 3 May 2021 14:55:22 +0200 Subject: [PATCH 01/14] proof of concept add test type on prints --- compiler/rustc_builtin_macros/src/test.rs | 4 ++ library/test/src/formatters/pretty.rs | 2 +- library/test/src/formatters/terse.rs | 2 +- library/test/src/tests.rs | 38 +++++++++++++++++++ library/test/src/types.rs | 24 ++++++++++++ src/librustdoc/doctest.rs | 4 +- src/test/rustdoc-ui/cfg-test.stdout | 4 +- .../doc-test-doctest-feature.stdout | 2 +- .../doc-test-rustdoc-feature.stdout | 2 +- src/test/rustdoc-ui/doctest-output.stdout | 6 +-- .../failed-doctest-compile-fail.stdout | 2 +- .../failed-doctest-missing-codes.stdout | 2 +- .../rustdoc-ui/failed-doctest-output.stdout | 4 +- .../failed-doctest-should-panic.stdout | 2 +- src/test/rustdoc-ui/issue-80992.stdout | 2 +- .../rustdoc-ui/issue-81662-shortness.stdout | 2 +- src/test/rustdoc-ui/no-run-flag.stdout | 14 +++---- .../rustdoc-ui/run-directory.correct.stdout | 2 +- .../rustdoc-ui/run-directory.incorrect.stdout | 2 +- src/test/rustdoc-ui/test-no_std.stdout | 2 +- src/test/rustdoc-ui/test-type.rs | 26 +++++++++++++ src/test/rustdoc-ui/test-type.stdout | 10 +++++ .../rustdoc-ui/unparseable-doc-test.stdout | 2 +- .../test-filter-multiple.run.stdout | 4 +- src/test/ui/test-attrs/test-type.rs | 28 ++++++++++++++ src/test/ui/test-attrs/test-type.run.stdout | 8 ++++ .../ui/test-panic-abort-nocapture.run.stdout | 8 ++-- src/test/ui/test-panic-abort.run.stdout | 10 ++--- src/test/ui/test-passed.run.stdout | 4 +- src/test/ui/test-thread-capture.run.stdout | 4 +- src/test/ui/test-thread-nocapture.run.stdout | 4 +- src/tools/compiletest/src/main.rs | 2 + 32 files changed, 187 insertions(+), 45 deletions(-) create mode 100644 src/test/rustdoc-ui/test-type.rs create mode 100644 src/test/rustdoc-ui/test-type.stdout create mode 100644 src/test/ui/test-attrs/test-type.rs create mode 100644 src/test/ui/test-attrs/test-type.run.stdout diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index e845f9ec55ad5..99544ddb66e66 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -254,6 +254,10 @@ pub fn expand_test_or_bench( "allow_fail", cx.expr_bool(sp, should_fail(&cx.sess, &item)), ), + // compile_fail: true | false + field("compile_fail", cx.expr_bool(sp, false)), + // no_run: true | false + field("no_run", cx.expr_bool(sp, false)), // should_panic: ... field( "should_panic", diff --git a/library/test/src/formatters/pretty.rs b/library/test/src/formatters/pretty.rs index 5e41d6d969234..00d4b18b30232 100644 --- a/library/test/src/formatters/pretty.rs +++ b/library/test/src/formatters/pretty.rs @@ -169,7 +169,7 @@ impl PrettyFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - self.write_plain(&format!("test {} ... ", name))?; + self.write_plain(&format!("test {} {} ... ", name, desc.test_mode_string()))?; Ok(()) } diff --git a/library/test/src/formatters/terse.rs b/library/test/src/formatters/terse.rs index 6f46f7255a47e..a68ceb404f9f7 100644 --- a/library/test/src/formatters/terse.rs +++ b/library/test/src/formatters/terse.rs @@ -158,7 +158,7 @@ impl TerseFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - self.write_plain(&format!("test {} ... ", name))?; + self.write_plain(&format!("test {} {} ... ", name, desc.test_mode_string()))?; Ok(()) } diff --git a/library/test/src/tests.rs b/library/test/src/tests.rs index 6a3f31b74ea59..794f727700476 100644 --- a/library/test/src/tests.rs +++ b/library/test/src/tests.rs @@ -61,6 +61,8 @@ fn one_ignored_one_unignored_test() -> Vec { ignore: true, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(move || {})), @@ -71,6 +73,8 @@ fn one_ignored_one_unignored_test() -> Vec { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(move || {})), @@ -89,6 +93,8 @@ pub fn do_not_run_ignored_tests() { ignore: true, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(f)), @@ -108,6 +114,8 @@ pub fn ignored_tests_result_in_ignored() { ignore: true, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(f)), @@ -131,6 +139,8 @@ fn test_should_panic() { ignore: false, should_panic: ShouldPanic::Yes, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(f)), @@ -154,6 +164,8 @@ fn test_should_panic_good_message() { ignore: false, should_panic: ShouldPanic::YesWithMessage("error message"), allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(f)), @@ -182,6 +194,8 @@ fn test_should_panic_bad_message() { ignore: false, should_panic: ShouldPanic::YesWithMessage(expected), allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(f)), @@ -214,6 +228,8 @@ fn test_should_panic_non_string_message_type() { ignore: false, should_panic: ShouldPanic::YesWithMessage(expected), allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(f)), @@ -238,6 +254,8 @@ fn test_should_panic_but_succeeds() { ignore: false, should_panic, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(f)), @@ -270,6 +288,8 @@ fn report_time_test_template(report_time: bool) -> Option { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(f)), @@ -303,6 +323,8 @@ fn time_test_failure_template(test_type: TestType) -> TestResult { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type, }, testfn: DynTestFn(Box::new(f)), @@ -340,6 +362,8 @@ fn typed_test_desc(test_type: TestType) -> TestDesc { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type, } } @@ -451,6 +475,8 @@ pub fn exclude_should_panic_option() { ignore: false, should_panic: ShouldPanic::Yes, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(move || {})), @@ -473,6 +499,8 @@ pub fn exact_filter_match() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(move || {})), @@ -565,6 +593,8 @@ pub fn sort_tests() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }, testfn: DynTestFn(Box::new(testfn)), @@ -642,6 +672,8 @@ pub fn test_bench_no_iter() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }; @@ -662,6 +694,8 @@ pub fn test_bench_iter() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }; @@ -676,6 +710,8 @@ fn should_sort_failures_before_printing_them() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }; @@ -684,6 +720,8 @@ fn should_sort_failures_before_printing_them() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + compile_fail: false, + no_run: false, test_type: TestType::Unknown, }; diff --git a/library/test/src/types.rs b/library/test/src/types.rs index c5d91f653b356..61c644f7972f8 100644 --- a/library/test/src/types.rs +++ b/library/test/src/types.rs @@ -124,6 +124,8 @@ pub struct TestDesc { pub ignore: bool, pub should_panic: options::ShouldPanic, pub allow_fail: bool, + pub compile_fail: bool, + pub no_run: bool, pub test_type: TestType, } @@ -140,6 +142,28 @@ impl TestDesc { } } } + + pub fn test_mode_string(&self) -> String { + if self.ignore { + return "ignore".to_string(); + } + match self.should_panic { + options::ShouldPanic::Yes | options::ShouldPanic::YesWithMessage(_) => { + return "should panic".to_string(); + } + _ => {} + } + if self.allow_fail { + return "allow fail".to_string(); + } + if self.compile_fail { + return "compile fail".to_string(); + } + if self.no_run { + return "compile".to_string(); + } + "run".to_string() + } } #[derive(Debug)] diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index c0157121e1923..8ef9170f91945 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -879,6 +879,7 @@ impl Tester for Collector { let target = self.options.target.clone(); let target_str = target.to_string(); let unused_externs = self.unused_extern_reports.clone(); + let no_run = config.no_run || options.no_run; if !config.compile_fail { self.compiling_test_count.fetch_add(1, Ordering::SeqCst); } @@ -934,13 +935,14 @@ impl Tester for Collector { // compiler failures are test failures should_panic: testing::ShouldPanic::No, allow_fail: config.allow_fail, + compile_fail: config.compile_fail, + no_run, test_type: testing::TestType::DocTest, }, testfn: testing::DynTestFn(box move || { let report_unused_externs = |uext| { unused_externs.lock().unwrap().push(uext); }; - let no_run = config.no_run || options.no_run; let res = run_test( &test, &cratename, diff --git a/src/test/rustdoc-ui/cfg-test.stdout b/src/test/rustdoc-ui/cfg-test.stdout index 2960ff8d3b473..fdd754609ef8c 100644 --- a/src/test/rustdoc-ui/cfg-test.stdout +++ b/src/test/rustdoc-ui/cfg-test.stdout @@ -1,7 +1,7 @@ running 2 tests -test $DIR/cfg-test.rs - Bar (line 27) ... ok -test $DIR/cfg-test.rs - Foo (line 19) ... ok +test $DIR/cfg-test.rs - Bar (line 27) run ... ok +test $DIR/cfg-test.rs - Foo (line 19) run ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doc-test-doctest-feature.stdout b/src/test/rustdoc-ui/doc-test-doctest-feature.stdout index d7de1f105228f..ecf5dcd056a32 100644 --- a/src/test/rustdoc-ui/doc-test-doctest-feature.stdout +++ b/src/test/rustdoc-ui/doc-test-doctest-feature.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/doc-test-doctest-feature.rs - Foo (line 9) ... ok +test $DIR/doc-test-doctest-feature.rs - Foo (line 9) run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout b/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout index 5b07fc4c87af5..7f900cb285801 100644 --- a/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout +++ b/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/doc-test-rustdoc-feature.rs - Foo (line 10) ... ok +test $DIR/doc-test-rustdoc-feature.rs - Foo (line 10) run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doctest-output.stdout b/src/test/rustdoc-ui/doctest-output.stdout index 35b0e366fb5cc..1b5857d251b40 100644 --- a/src/test/rustdoc-ui/doctest-output.stdout +++ b/src/test/rustdoc-ui/doctest-output.stdout @@ -1,8 +1,8 @@ running 3 tests -test $DIR/doctest-output.rs - (line 8) ... ok -test $DIR/doctest-output.rs - ExpandedStruct (line 24) ... ok -test $DIR/doctest-output.rs - foo::bar (line 18) ... ok +test $DIR/doctest-output.rs - (line 8) run ... ok +test $DIR/doctest-output.rs - ExpandedStruct (line 24) run ... ok +test $DIR/doctest-output.rs - foo::bar (line 18) run ... ok test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/failed-doctest-compile-fail.stdout b/src/test/rustdoc-ui/failed-doctest-compile-fail.stdout index b8bb5ccb40329..dc811df609cc5 100644 --- a/src/test/rustdoc-ui/failed-doctest-compile-fail.stdout +++ b/src/test/rustdoc-ui/failed-doctest-compile-fail.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/failed-doctest-compile-fail.rs - Foo (line 9) ... FAILED +test $DIR/failed-doctest-compile-fail.rs - Foo (line 9) compile fail ... FAILED failures: diff --git a/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout b/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout index 7367a7d651919..a76511eb29e7d 100644 --- a/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout +++ b/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/failed-doctest-missing-codes.rs - Foo (line 9) ... FAILED +test $DIR/failed-doctest-missing-codes.rs - Foo (line 9) compile fail ... FAILED failures: diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index 6dfe648f8549e..83c8c5301e006 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -1,7 +1,7 @@ running 2 tests -test $DIR/failed-doctest-output.rs - OtherStruct (line 22) ... FAILED -test $DIR/failed-doctest-output.rs - SomeStruct (line 12) ... FAILED +test $DIR/failed-doctest-output.rs - OtherStruct (line 22) run ... FAILED +test $DIR/failed-doctest-output.rs - SomeStruct (line 12) run ... FAILED failures: diff --git a/src/test/rustdoc-ui/failed-doctest-should-panic.stdout b/src/test/rustdoc-ui/failed-doctest-should-panic.stdout index 57a20092a5d6c..e3d0216441b84 100644 --- a/src/test/rustdoc-ui/failed-doctest-should-panic.stdout +++ b/src/test/rustdoc-ui/failed-doctest-should-panic.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/failed-doctest-should-panic.rs - Foo (line 9) ... FAILED +test $DIR/failed-doctest-should-panic.rs - Foo (line 9) run ... FAILED failures: diff --git a/src/test/rustdoc-ui/issue-80992.stdout b/src/test/rustdoc-ui/issue-80992.stdout index 1dd19f468274c..e7110dee4fb07 100644 --- a/src/test/rustdoc-ui/issue-80992.stdout +++ b/src/test/rustdoc-ui/issue-80992.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/issue-80992.rs - test (line 7) ... ok +test $DIR/issue-80992.rs - test (line 7) compile fail ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/issue-81662-shortness.stdout b/src/test/rustdoc-ui/issue-81662-shortness.stdout index 748113be3a26d..3c2901e70f0ee 100644 --- a/src/test/rustdoc-ui/issue-81662-shortness.stdout +++ b/src/test/rustdoc-ui/issue-81662-shortness.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/issue-81662-shortness.rs - foo (line 6) ... FAILED +test $DIR/issue-81662-shortness.rs - foo (line 6) run ... FAILED failures: diff --git a/src/test/rustdoc-ui/no-run-flag.stdout b/src/test/rustdoc-ui/no-run-flag.stdout index d92f5da833567..418691e4f0cbe 100644 --- a/src/test/rustdoc-ui/no-run-flag.stdout +++ b/src/test/rustdoc-ui/no-run-flag.stdout @@ -1,12 +1,12 @@ running 7 tests -test $DIR/no-run-flag.rs - f (line 11) ... ok -test $DIR/no-run-flag.rs - f (line 14) ... ignored -test $DIR/no-run-flag.rs - f (line 17) ... ok -test $DIR/no-run-flag.rs - f (line 23) ... ok -test $DIR/no-run-flag.rs - f (line 28) ... ok -test $DIR/no-run-flag.rs - f (line 32) ... ok -test $DIR/no-run-flag.rs - f (line 8) ... ok +test $DIR/no-run-flag.rs - f (line 11) compile ... ok +test $DIR/no-run-flag.rs - f (line 14) ignore ... ignored +test $DIR/no-run-flag.rs - f (line 17) compile ... ok +test $DIR/no-run-flag.rs - f (line 23) compile fail ... ok +test $DIR/no-run-flag.rs - f (line 28) compile ... ok +test $DIR/no-run-flag.rs - f (line 32) compile ... ok +test $DIR/no-run-flag.rs - f (line 8) compile ... ok test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/run-directory.correct.stdout b/src/test/rustdoc-ui/run-directory.correct.stdout index e9b2754794a78..a5bc41ece9912 100644 --- a/src/test/rustdoc-ui/run-directory.correct.stdout +++ b/src/test/rustdoc-ui/run-directory.correct.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/run-directory.rs - foo (line 10) ... ok +test $DIR/run-directory.rs - foo (line 10) run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/run-directory.incorrect.stdout b/src/test/rustdoc-ui/run-directory.incorrect.stdout index 97a5dbc5c0cd1..542043bc43758 100644 --- a/src/test/rustdoc-ui/run-directory.incorrect.stdout +++ b/src/test/rustdoc-ui/run-directory.incorrect.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/run-directory.rs - foo (line 19) ... ok +test $DIR/run-directory.rs - foo (line 19) run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/test-no_std.stdout b/src/test/rustdoc-ui/test-no_std.stdout index 8d5a30804c1e2..82dbffcbd55dd 100644 --- a/src/test/rustdoc-ui/test-no_std.stdout +++ b/src/test/rustdoc-ui/test-no_std.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/test-no_std.rs - f (line 10) ... ok +test $DIR/test-no_std.rs - f (line 10) run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/test-type.rs b/src/test/rustdoc-ui/test-type.rs new file mode 100644 index 0000000000000..882da5c2503fe --- /dev/null +++ b/src/test/rustdoc-ui/test-type.rs @@ -0,0 +1,26 @@ +// compile-flags: --test --test-args=--test-threads=1 +// check-pass +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" +// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" + +/// ``` +/// let a = true; +/// ``` +/// ```should_panic +/// panic!() +/// ``` +/// ```ignore (incomplete-code) +/// fn foo() { +/// ``` +/// ```no_run +/// loop { +/// println!("Hello, world"); +/// } +/// ``` +/// fails to compile +/// ```compile_fail +/// let x = 5; +/// x += 2; // shouldn't compile! +/// ``` + +pub fn f() {} diff --git a/src/test/rustdoc-ui/test-type.stdout b/src/test/rustdoc-ui/test-type.stdout new file mode 100644 index 0000000000000..8f36d643b2f98 --- /dev/null +++ b/src/test/rustdoc-ui/test-type.stdout @@ -0,0 +1,10 @@ + +running 5 tests +test $DIR/test-type.rs - f (line 12) ignore ... ignored +test $DIR/test-type.rs - f (line 15) compile ... ok +test $DIR/test-type.rs - f (line 21) compile fail ... ok +test $DIR/test-type.rs - f (line 6) run ... ok +test $DIR/test-type.rs - f (line 9) run ... ok + +test result: ok. 4 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/src/test/rustdoc-ui/unparseable-doc-test.stdout b/src/test/rustdoc-ui/unparseable-doc-test.stdout index 2641c66f25e77..dbbb6541b9718 100644 --- a/src/test/rustdoc-ui/unparseable-doc-test.stdout +++ b/src/test/rustdoc-ui/unparseable-doc-test.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/unparseable-doc-test.rs - foo (line 7) ... FAILED +test $DIR/unparseable-doc-test.rs - foo (line 7) run ... FAILED failures: diff --git a/src/test/ui/test-attrs/test-filter-multiple.run.stdout b/src/test/ui/test-attrs/test-filter-multiple.run.stdout index 1aa684ed5073a..6389d7f998ffb 100644 --- a/src/test/ui/test-attrs/test-filter-multiple.run.stdout +++ b/src/test/ui/test-attrs/test-filter-multiple.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test test1 ... ok -test test2 ... ok +test test1 run ... ok +test test2 run ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in $TIME diff --git a/src/test/ui/test-attrs/test-type.rs b/src/test/ui/test-attrs/test-type.rs new file mode 100644 index 0000000000000..3f0fa81373f10 --- /dev/null +++ b/src/test/ui/test-attrs/test-type.rs @@ -0,0 +1,28 @@ +// compile-flags: --test +// run-flags: --test-threads=1 +// check-run-results +// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" +// ignore-emscripten no threads support +// run-pass + + +#[test] +fn test_ok() { + let _a = true; +} + +#[test] +#[should_panic] +fn test_panic() { + panic!(); +} + +#[test] +#[ignore] +fn test_no_run() { + loop{ + println!("Hello, world"); + } +} + +fn main() {} diff --git a/src/test/ui/test-attrs/test-type.run.stdout b/src/test/ui/test-attrs/test-type.run.stdout new file mode 100644 index 0000000000000..5f10c784f891f --- /dev/null +++ b/src/test/ui/test-attrs/test-type.run.stdout @@ -0,0 +1,8 @@ + +running 3 tests +test test_no_run ignore ... ignored +test test_ok run ... ok +test test_panic should panic ... ok + +test result: ok. 2 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/src/test/ui/test-panic-abort-nocapture.run.stdout b/src/test/ui/test-panic-abort-nocapture.run.stdout index 15b19676a7c2d..29d5172ce8c87 100644 --- a/src/test/ui/test-panic-abort-nocapture.run.stdout +++ b/src/test/ui/test-panic-abort-nocapture.run.stdout @@ -1,12 +1,12 @@ running 4 tests -test it_fails ... about to fail +test it_fails run ... about to fail FAILED -test it_panics ... about to panic +test it_panics should panic ... about to panic ok -test it_works ... about to succeed +test it_works run ... about to succeed ok -test it_writes_to_stdio ... hello, world +test it_writes_to_stdio run ... hello, world testing123 ok diff --git a/src/test/ui/test-panic-abort.run.stdout b/src/test/ui/test-panic-abort.run.stdout index 467f834afecbf..2842f08f6cc09 100644 --- a/src/test/ui/test-panic-abort.run.stdout +++ b/src/test/ui/test-panic-abort.run.stdout @@ -1,10 +1,10 @@ running 5 tests -test it_exits ... FAILED -test it_fails ... FAILED -test it_panics ... ok -test it_works ... ok -test no_residual_environment ... ok +test it_exits run ... FAILED +test it_fails run ... FAILED +test it_panics should panic ... ok +test it_works run ... ok +test no_residual_environment run ... ok failures: diff --git a/src/test/ui/test-passed.run.stdout b/src/test/ui/test-passed.run.stdout index 17f70d607494e..cd4b0e466a3fb 100644 --- a/src/test/ui/test-passed.run.stdout +++ b/src/test/ui/test-passed.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test it_works ... ok -test it_works_too ... ok +test it_works run ... ok +test it_works_too run ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/ui/test-thread-capture.run.stdout b/src/test/ui/test-thread-capture.run.stdout index 487cfb55eb473..db9d90f20f2d4 100644 --- a/src/test/ui/test-thread-capture.run.stdout +++ b/src/test/ui/test-thread-capture.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test thready_fail ... FAILED -test thready_pass ... ok +test thready_fail run ... FAILED +test thready_pass run ... ok failures: diff --git a/src/test/ui/test-thread-nocapture.run.stdout b/src/test/ui/test-thread-nocapture.run.stdout index 9d2da50826c25..42e6d40a4d11e 100644 --- a/src/test/ui/test-thread-nocapture.run.stdout +++ b/src/test/ui/test-thread-nocapture.run.stdout @@ -1,11 +1,11 @@ running 2 tests -test thready_fail ... fee +test thready_fail run ... fee fie foe fum FAILED -test thready_pass ... fee +test thready_pass run ... fee fie foe fum diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index d1798a52df7c4..f3751ff244fd0 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -649,6 +649,8 @@ fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> Vec Date: Mon, 3 May 2021 20:16:44 +0200 Subject: [PATCH 02/14] change based on review --- library/test/src/formatters/pretty.rs | 2 +- library/test/src/formatters/terse.rs | 2 +- library/test/src/types.rs | 16 ++++++++-------- src/test/rustdoc-ui/cfg-test.stdout | 4 ++-- .../rustdoc-ui/doc-test-doctest-feature.stdout | 2 +- .../rustdoc-ui/doc-test-rustdoc-feature.stdout | 2 +- src/test/rustdoc-ui/doctest-output.stdout | 6 +++--- .../failed-doctest-compile-fail.stdout | 2 +- .../failed-doctest-missing-codes.stdout | 2 +- src/test/rustdoc-ui/failed-doctest-output.stdout | 4 ++-- .../failed-doctest-should-panic.stdout | 2 +- src/test/rustdoc-ui/issue-80992.stdout | 2 +- src/test/rustdoc-ui/issue-81662-shortness.stdout | 2 +- src/test/rustdoc-ui/no-run-flag.stdout | 14 +++++++------- src/test/rustdoc-ui/run-directory.correct.stdout | 2 +- .../rustdoc-ui/run-directory.incorrect.stdout | 2 +- src/test/rustdoc-ui/test-no_std.stdout | 2 +- src/test/rustdoc-ui/test-type.stdout | 10 +++++----- src/test/rustdoc-ui/unparseable-doc-test.stdout | 2 +- .../test-attrs/test-filter-multiple.run.stdout | 4 ++-- src/test/ui/test-attrs/test-type.run.stdout | 6 +++--- .../ui/test-panic-abort-nocapture.run.stdout | 8 ++++---- src/test/ui/test-panic-abort.run.stdout | 10 +++++----- src/test/ui/test-passed.run.stdout | 4 ++-- src/test/ui/test-thread-capture.run.stdout | 4 ++-- src/test/ui/test-thread-nocapture.run.stdout | 4 ++-- 26 files changed, 60 insertions(+), 60 deletions(-) diff --git a/library/test/src/formatters/pretty.rs b/library/test/src/formatters/pretty.rs index 00d4b18b30232..543b9a6924ac6 100644 --- a/library/test/src/formatters/pretty.rs +++ b/library/test/src/formatters/pretty.rs @@ -169,7 +169,7 @@ impl PrettyFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - self.write_plain(&format!("test {} {} ... ", name, desc.test_mode_string()))?; + self.write_plain(&format!("test {} - {} ... ", name, desc.test_mode_string()))?; Ok(()) } diff --git a/library/test/src/formatters/terse.rs b/library/test/src/formatters/terse.rs index a68ceb404f9f7..286b50b525d4b 100644 --- a/library/test/src/formatters/terse.rs +++ b/library/test/src/formatters/terse.rs @@ -158,7 +158,7 @@ impl TerseFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - self.write_plain(&format!("test {} {} ... ", name, desc.test_mode_string()))?; + self.write_plain(&format!("test {} - {} ... ", name, desc.test_mode_string()))?; Ok(()) } diff --git a/library/test/src/types.rs b/library/test/src/types.rs index 61c644f7972f8..a2c3d5fa8eeb4 100644 --- a/library/test/src/types.rs +++ b/library/test/src/types.rs @@ -143,26 +143,26 @@ impl TestDesc { } } - pub fn test_mode_string(&self) -> String { + pub fn test_mode_string(&self) -> &'static str { if self.ignore { - return "ignore".to_string(); + return &"ignore"; } match self.should_panic { options::ShouldPanic::Yes | options::ShouldPanic::YesWithMessage(_) => { - return "should panic".to_string(); + return &"should panic"; } - _ => {} + options::ShouldPanic::No => {} } if self.allow_fail { - return "allow fail".to_string(); + return &"allow fail"; } if self.compile_fail { - return "compile fail".to_string(); + return &"compile fail"; } if self.no_run { - return "compile".to_string(); + return &"compile"; } - "run".to_string() + &"run" } } diff --git a/src/test/rustdoc-ui/cfg-test.stdout b/src/test/rustdoc-ui/cfg-test.stdout index fdd754609ef8c..42d3fbb48dd86 100644 --- a/src/test/rustdoc-ui/cfg-test.stdout +++ b/src/test/rustdoc-ui/cfg-test.stdout @@ -1,7 +1,7 @@ running 2 tests -test $DIR/cfg-test.rs - Bar (line 27) run ... ok -test $DIR/cfg-test.rs - Foo (line 19) run ... ok +test $DIR/cfg-test.rs - Bar (line 27) - run ... ok +test $DIR/cfg-test.rs - Foo (line 19) - run ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doc-test-doctest-feature.stdout b/src/test/rustdoc-ui/doc-test-doctest-feature.stdout index ecf5dcd056a32..cfcb60332f46b 100644 --- a/src/test/rustdoc-ui/doc-test-doctest-feature.stdout +++ b/src/test/rustdoc-ui/doc-test-doctest-feature.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/doc-test-doctest-feature.rs - Foo (line 9) run ... ok +test $DIR/doc-test-doctest-feature.rs - Foo (line 9) - run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout b/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout index 7f900cb285801..8d7f1ad21d1da 100644 --- a/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout +++ b/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/doc-test-rustdoc-feature.rs - Foo (line 10) run ... ok +test $DIR/doc-test-rustdoc-feature.rs - Foo (line 10) - run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doctest-output.stdout b/src/test/rustdoc-ui/doctest-output.stdout index 1b5857d251b40..7a07d273e2691 100644 --- a/src/test/rustdoc-ui/doctest-output.stdout +++ b/src/test/rustdoc-ui/doctest-output.stdout @@ -1,8 +1,8 @@ running 3 tests -test $DIR/doctest-output.rs - (line 8) run ... ok -test $DIR/doctest-output.rs - ExpandedStruct (line 24) run ... ok -test $DIR/doctest-output.rs - foo::bar (line 18) run ... ok +test $DIR/doctest-output.rs - (line 8) - run ... ok +test $DIR/doctest-output.rs - ExpandedStruct (line 24) - run ... ok +test $DIR/doctest-output.rs - foo::bar (line 18) - run ... ok test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/failed-doctest-compile-fail.stdout b/src/test/rustdoc-ui/failed-doctest-compile-fail.stdout index dc811df609cc5..af3a90a74100f 100644 --- a/src/test/rustdoc-ui/failed-doctest-compile-fail.stdout +++ b/src/test/rustdoc-ui/failed-doctest-compile-fail.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/failed-doctest-compile-fail.rs - Foo (line 9) compile fail ... FAILED +test $DIR/failed-doctest-compile-fail.rs - Foo (line 9) - compile fail ... FAILED failures: diff --git a/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout b/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout index a76511eb29e7d..bacbb47b5f9ff 100644 --- a/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout +++ b/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/failed-doctest-missing-codes.rs - Foo (line 9) compile fail ... FAILED +test $DIR/failed-doctest-missing-codes.rs - Foo (line 9) - compile fail ... FAILED failures: diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index 83c8c5301e006..7ba599ff11b90 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -1,7 +1,7 @@ running 2 tests -test $DIR/failed-doctest-output.rs - OtherStruct (line 22) run ... FAILED -test $DIR/failed-doctest-output.rs - SomeStruct (line 12) run ... FAILED +test $DIR/failed-doctest-output.rs - OtherStruct (line 22) - run ... FAILED +test $DIR/failed-doctest-output.rs - SomeStruct (line 12) - run ... FAILED failures: diff --git a/src/test/rustdoc-ui/failed-doctest-should-panic.stdout b/src/test/rustdoc-ui/failed-doctest-should-panic.stdout index e3d0216441b84..6bd21423e69eb 100644 --- a/src/test/rustdoc-ui/failed-doctest-should-panic.stdout +++ b/src/test/rustdoc-ui/failed-doctest-should-panic.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/failed-doctest-should-panic.rs - Foo (line 9) run ... FAILED +test $DIR/failed-doctest-should-panic.rs - Foo (line 9) - run ... FAILED failures: diff --git a/src/test/rustdoc-ui/issue-80992.stdout b/src/test/rustdoc-ui/issue-80992.stdout index e7110dee4fb07..d2b1cd1d550cf 100644 --- a/src/test/rustdoc-ui/issue-80992.stdout +++ b/src/test/rustdoc-ui/issue-80992.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/issue-80992.rs - test (line 7) compile fail ... ok +test $DIR/issue-80992.rs - test (line 7) - compile fail ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/issue-81662-shortness.stdout b/src/test/rustdoc-ui/issue-81662-shortness.stdout index 3c2901e70f0ee..f9fdf7048d887 100644 --- a/src/test/rustdoc-ui/issue-81662-shortness.stdout +++ b/src/test/rustdoc-ui/issue-81662-shortness.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/issue-81662-shortness.rs - foo (line 6) run ... FAILED +test $DIR/issue-81662-shortness.rs - foo (line 6) - run ... FAILED failures: diff --git a/src/test/rustdoc-ui/no-run-flag.stdout b/src/test/rustdoc-ui/no-run-flag.stdout index 418691e4f0cbe..22d927317b317 100644 --- a/src/test/rustdoc-ui/no-run-flag.stdout +++ b/src/test/rustdoc-ui/no-run-flag.stdout @@ -1,12 +1,12 @@ running 7 tests -test $DIR/no-run-flag.rs - f (line 11) compile ... ok -test $DIR/no-run-flag.rs - f (line 14) ignore ... ignored -test $DIR/no-run-flag.rs - f (line 17) compile ... ok -test $DIR/no-run-flag.rs - f (line 23) compile fail ... ok -test $DIR/no-run-flag.rs - f (line 28) compile ... ok -test $DIR/no-run-flag.rs - f (line 32) compile ... ok -test $DIR/no-run-flag.rs - f (line 8) compile ... ok +test $DIR/no-run-flag.rs - f (line 11) - compile ... ok +test $DIR/no-run-flag.rs - f (line 14) - ignore ... ignored +test $DIR/no-run-flag.rs - f (line 17) - compile ... ok +test $DIR/no-run-flag.rs - f (line 23) - compile fail ... ok +test $DIR/no-run-flag.rs - f (line 28) - compile ... ok +test $DIR/no-run-flag.rs - f (line 32) - compile ... ok +test $DIR/no-run-flag.rs - f (line 8) - compile ... ok test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/run-directory.correct.stdout b/src/test/rustdoc-ui/run-directory.correct.stdout index a5bc41ece9912..1bb84a868a414 100644 --- a/src/test/rustdoc-ui/run-directory.correct.stdout +++ b/src/test/rustdoc-ui/run-directory.correct.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/run-directory.rs - foo (line 10) run ... ok +test $DIR/run-directory.rs - foo (line 10) - run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/run-directory.incorrect.stdout b/src/test/rustdoc-ui/run-directory.incorrect.stdout index 542043bc43758..7f6bba8fe471c 100644 --- a/src/test/rustdoc-ui/run-directory.incorrect.stdout +++ b/src/test/rustdoc-ui/run-directory.incorrect.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/run-directory.rs - foo (line 19) run ... ok +test $DIR/run-directory.rs - foo (line 19) - run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/test-no_std.stdout b/src/test/rustdoc-ui/test-no_std.stdout index 82dbffcbd55dd..35d44fa6bbd05 100644 --- a/src/test/rustdoc-ui/test-no_std.stdout +++ b/src/test/rustdoc-ui/test-no_std.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/test-no_std.rs - f (line 10) run ... ok +test $DIR/test-no_std.rs - f (line 10) - run ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/test-type.stdout b/src/test/rustdoc-ui/test-type.stdout index 8f36d643b2f98..fb6c036a60817 100644 --- a/src/test/rustdoc-ui/test-type.stdout +++ b/src/test/rustdoc-ui/test-type.stdout @@ -1,10 +1,10 @@ running 5 tests -test $DIR/test-type.rs - f (line 12) ignore ... ignored -test $DIR/test-type.rs - f (line 15) compile ... ok -test $DIR/test-type.rs - f (line 21) compile fail ... ok -test $DIR/test-type.rs - f (line 6) run ... ok -test $DIR/test-type.rs - f (line 9) run ... ok +test $DIR/test-type.rs - f (line 12) - ignore ... ignored +test $DIR/test-type.rs - f (line 15) - compile ... ok +test $DIR/test-type.rs - f (line 21) - compile fail ... ok +test $DIR/test-type.rs - f (line 6) - run ... ok +test $DIR/test-type.rs - f (line 9) - run ... ok test result: ok. 4 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/unparseable-doc-test.stdout b/src/test/rustdoc-ui/unparseable-doc-test.stdout index dbbb6541b9718..13526acfc479d 100644 --- a/src/test/rustdoc-ui/unparseable-doc-test.stdout +++ b/src/test/rustdoc-ui/unparseable-doc-test.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/unparseable-doc-test.rs - foo (line 7) run ... FAILED +test $DIR/unparseable-doc-test.rs - foo (line 7) - run ... FAILED failures: diff --git a/src/test/ui/test-attrs/test-filter-multiple.run.stdout b/src/test/ui/test-attrs/test-filter-multiple.run.stdout index 6389d7f998ffb..5d6d5cbd3c3f4 100644 --- a/src/test/ui/test-attrs/test-filter-multiple.run.stdout +++ b/src/test/ui/test-attrs/test-filter-multiple.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test test1 run ... ok -test test2 run ... ok +test test1 - run ... ok +test test2 - run ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in $TIME diff --git a/src/test/ui/test-attrs/test-type.run.stdout b/src/test/ui/test-attrs/test-type.run.stdout index 5f10c784f891f..9f789526615d9 100644 --- a/src/test/ui/test-attrs/test-type.run.stdout +++ b/src/test/ui/test-attrs/test-type.run.stdout @@ -1,8 +1,8 @@ running 3 tests -test test_no_run ignore ... ignored -test test_ok run ... ok -test test_panic should panic ... ok +test test_no_run - ignore ... ignored +test test_ok - run ... ok +test test_panic - should panic ... ok test result: ok. 2 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/ui/test-panic-abort-nocapture.run.stdout b/src/test/ui/test-panic-abort-nocapture.run.stdout index 29d5172ce8c87..e335cf05153ba 100644 --- a/src/test/ui/test-panic-abort-nocapture.run.stdout +++ b/src/test/ui/test-panic-abort-nocapture.run.stdout @@ -1,12 +1,12 @@ running 4 tests -test it_fails run ... about to fail +test it_fails - run ... about to fail FAILED -test it_panics should panic ... about to panic +test it_panics - should panic ... about to panic ok -test it_works run ... about to succeed +test it_works - run ... about to succeed ok -test it_writes_to_stdio run ... hello, world +test it_writes_to_stdio - run ... hello, world testing123 ok diff --git a/src/test/ui/test-panic-abort.run.stdout b/src/test/ui/test-panic-abort.run.stdout index 2842f08f6cc09..0d9de10c98189 100644 --- a/src/test/ui/test-panic-abort.run.stdout +++ b/src/test/ui/test-panic-abort.run.stdout @@ -1,10 +1,10 @@ running 5 tests -test it_exits run ... FAILED -test it_fails run ... FAILED -test it_panics should panic ... ok -test it_works run ... ok -test no_residual_environment run ... ok +test it_exits - run ... FAILED +test it_fails - run ... FAILED +test it_panics - should panic ... ok +test it_works - run ... ok +test no_residual_environment - run ... ok failures: diff --git a/src/test/ui/test-passed.run.stdout b/src/test/ui/test-passed.run.stdout index cd4b0e466a3fb..995643a62c88f 100644 --- a/src/test/ui/test-passed.run.stdout +++ b/src/test/ui/test-passed.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test it_works run ... ok -test it_works_too run ... ok +test it_works - run ... ok +test it_works_too - run ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/ui/test-thread-capture.run.stdout b/src/test/ui/test-thread-capture.run.stdout index db9d90f20f2d4..ce9ec63b526c9 100644 --- a/src/test/ui/test-thread-capture.run.stdout +++ b/src/test/ui/test-thread-capture.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test thready_fail run ... FAILED -test thready_pass run ... ok +test thready_fail - run ... FAILED +test thready_pass - run ... ok failures: diff --git a/src/test/ui/test-thread-nocapture.run.stdout b/src/test/ui/test-thread-nocapture.run.stdout index 42e6d40a4d11e..bd1971ab7d310 100644 --- a/src/test/ui/test-thread-nocapture.run.stdout +++ b/src/test/ui/test-thread-nocapture.run.stdout @@ -1,11 +1,11 @@ running 2 tests -test thready_fail run ... fee +test thready_fail - run ... fee fie foe fum FAILED -test thready_pass run ... fee +test thready_pass - run ... fee fie foe fum From f6b8b780633798477bf0b13e01bfec8e1ab76856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Sun, 9 May 2021 13:37:09 +0200 Subject: [PATCH 03/14] add bootstrap cfg --- library/test/src/formatters/pretty.rs | 2 +- library/test/src/formatters/terse.rs | 2 +- library/test/src/tests.rs | 38 +++++++++++++++++++++++++++ library/test/src/types.rs | 10 ++++++- src/librustdoc/doctest.rs | 2 ++ src/tools/compiletest/src/main.rs | 2 ++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/library/test/src/formatters/pretty.rs b/library/test/src/formatters/pretty.rs index 543b9a6924ac6..c1a0bb9f3e1e7 100644 --- a/library/test/src/formatters/pretty.rs +++ b/library/test/src/formatters/pretty.rs @@ -169,7 +169,7 @@ impl PrettyFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - self.write_plain(&format!("test {} - {} ... ", name, desc.test_mode_string()))?; + self.write_plain(&format!("test {} - {} ... ", name, desc.test_mode()))?; Ok(()) } diff --git a/library/test/src/formatters/terse.rs b/library/test/src/formatters/terse.rs index 286b50b525d4b..a9589829ad270 100644 --- a/library/test/src/formatters/terse.rs +++ b/library/test/src/formatters/terse.rs @@ -158,7 +158,7 @@ impl TerseFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - self.write_plain(&format!("test {} - {} ... ", name, desc.test_mode_string()))?; + self.write_plain(&format!("test {} - {} ... ", name, desc.test_mode()))?; Ok(()) } diff --git a/library/test/src/tests.rs b/library/test/src/tests.rs index 794f727700476..5a4a540b04eb0 100644 --- a/library/test/src/tests.rs +++ b/library/test/src/tests.rs @@ -61,7 +61,9 @@ fn one_ignored_one_unignored_test() -> Vec { ignore: true, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -73,7 +75,9 @@ fn one_ignored_one_unignored_test() -> Vec { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -93,7 +97,9 @@ pub fn do_not_run_ignored_tests() { ignore: true, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -114,7 +120,9 @@ pub fn ignored_tests_result_in_ignored() { ignore: true, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -139,7 +147,9 @@ fn test_should_panic() { ignore: false, should_panic: ShouldPanic::Yes, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -164,7 +174,9 @@ fn test_should_panic_good_message() { ignore: false, should_panic: ShouldPanic::YesWithMessage("error message"), allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -194,7 +206,9 @@ fn test_should_panic_bad_message() { ignore: false, should_panic: ShouldPanic::YesWithMessage(expected), allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -228,7 +242,9 @@ fn test_should_panic_non_string_message_type() { ignore: false, should_panic: ShouldPanic::YesWithMessage(expected), allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -254,7 +270,9 @@ fn test_should_panic_but_succeeds() { ignore: false, should_panic, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -288,7 +306,9 @@ fn report_time_test_template(report_time: bool) -> Option { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -323,7 +343,9 @@ fn time_test_failure_template(test_type: TestType) -> TestResult { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type, }, @@ -362,7 +384,9 @@ fn typed_test_desc(test_type: TestType) -> TestDesc { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type, } @@ -475,7 +499,9 @@ pub fn exclude_should_panic_option() { ignore: false, should_panic: ShouldPanic::Yes, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -499,7 +525,9 @@ pub fn exact_filter_match() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -593,7 +621,9 @@ pub fn sort_tests() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }, @@ -672,7 +702,9 @@ pub fn test_bench_no_iter() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }; @@ -694,7 +726,9 @@ pub fn test_bench_iter() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }; @@ -710,7 +744,9 @@ fn should_sort_failures_before_printing_them() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }; @@ -720,7 +756,9 @@ fn should_sort_failures_before_printing_them() { ignore: false, should_panic: ShouldPanic::No, allow_fail: false, + #[cfg(not(bootstrap))] compile_fail: false, + #[cfg(not(bootstrap))] no_run: false, test_type: TestType::Unknown, }; diff --git a/library/test/src/types.rs b/library/test/src/types.rs index a2c3d5fa8eeb4..4cbdc7affc657 100644 --- a/library/test/src/types.rs +++ b/library/test/src/types.rs @@ -124,7 +124,9 @@ pub struct TestDesc { pub ignore: bool, pub should_panic: options::ShouldPanic, pub allow_fail: bool, + #[cfg(not(bootstrap))] pub compile_fail: bool, + #[cfg(not(bootstrap))] pub no_run: bool, pub test_type: TestType, } @@ -143,7 +145,8 @@ impl TestDesc { } } - pub fn test_mode_string(&self) -> &'static str { + #[cfg(not(bootstrap))] + pub fn test_mode(&self) -> &'static str { if self.ignore { return &"ignore"; } @@ -164,6 +167,11 @@ impl TestDesc { } &"run" } + + #[cfg(bootstrap)] + pub fn test_mode(&self) -> &'static str { + &"" + } } #[derive(Debug)] diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 8ef9170f91945..c33d0ba4e5745 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -935,7 +935,9 @@ impl Tester for Collector { // compiler failures are test failures should_panic: testing::ShouldPanic::No, allow_fail: config.allow_fail, + #[cfg(not(bootstrap))] compile_fail: config.compile_fail, + #[cfg(not(bootstrap))] no_run, test_type: testing::TestType::DocTest, }, diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index f3751ff244fd0..0aa1f336b6d48 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -649,7 +649,9 @@ fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> Vec Date: Sun, 9 May 2021 14:46:00 +0200 Subject: [PATCH 04/14] fix compiletest to search for two dash and run make fulldeps test --- src/test/run-make-fulldeps/issue-22131/Makefile | 2 +- src/test/run-make-fulldeps/test-harness/Makefile | 2 +- src/tools/compiletest/src/runtest.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/run-make-fulldeps/issue-22131/Makefile b/src/test/run-make-fulldeps/issue-22131/Makefile index d76aaf5c146db..5f721ef313057 100644 --- a/src/test/run-make-fulldeps/issue-22131/Makefile +++ b/src/test/run-make-fulldeps/issue-22131/Makefile @@ -4,4 +4,4 @@ all: foo.rs $(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs $(RUSTDOC) --test --cfg 'feature="bar"' \ -L $(TMPDIR) foo.rs |\ - $(CGREP) 'foo.rs - foo (line 1) ... ok' + $(CGREP) 'foo.rs - foo (line 1) - run ... ok' diff --git a/src/test/run-make-fulldeps/test-harness/Makefile b/src/test/run-make-fulldeps/test-harness/Makefile index 39477c07ced7c..1f3b112d6afe4 100644 --- a/src/test/run-make-fulldeps/test-harness/Makefile +++ b/src/test/run-make-fulldeps/test-harness/Makefile @@ -3,6 +3,6 @@ all: # check that #[cfg_attr(..., ignore)] does the right thing. $(RUSTC) --test test-ignore-cfg.rs --cfg ignorecfg - $(call RUN,test-ignore-cfg) | $(CGREP) 'shouldnotignore ... ok' 'shouldignore ... ignored' + $(call RUN,test-ignore-cfg) | $(CGREP) 'shouldnotignore - run ... ok' 'shouldignore - ignore ... ignored' $(call RUN,test-ignore-cfg --quiet) | $(CGREP) -e "^i\.$$" $(call RUN,test-ignore-cfg --quiet) | $(CGREP) -v 'should' diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ecbaccf744dcd..0898e9ef2f630 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2638,7 +2638,7 @@ impl<'test> TestCx<'test> { let mut tested = 0; for _ in res.stdout.split('\n').filter(|s| s.starts_with("test ")).inspect(|s| { let tmp: Vec<&str> = s.split(" - ").collect(); - if tmp.len() == 2 { + if tmp.len() == 3 { let path = tmp[0].rsplit("test ").next().unwrap(); if let Some(ref mut v) = files.get_mut(&path.replace('\\', "/")) { tested += 1; From 3d8180635289437ac96b20ec94419394194f7c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Sun, 16 May 2021 17:27:30 +0200 Subject: [PATCH 05/14] remove mode for run and ignore tests --- library/test/src/formatters/pretty.rs | 7 ++++++- library/test/src/formatters/terse.rs | 7 ++++++- library/test/src/types.rs | 4 ++-- src/test/run-make-fulldeps/issue-22131/Makefile | 2 +- src/test/run-make-fulldeps/test-harness/Makefile | 2 +- src/test/rustdoc-ui/cfg-test.stdout | 4 ++-- src/test/rustdoc-ui/doc-test-doctest-feature.stdout | 2 +- src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout | 2 +- src/test/rustdoc-ui/doctest-output.stdout | 6 +++--- src/test/rustdoc-ui/failed-doctest-output.stdout | 4 ++-- src/test/rustdoc-ui/failed-doctest-should-panic.stdout | 2 +- src/test/rustdoc-ui/issue-81662-shortness.stdout | 2 +- src/test/rustdoc-ui/no-run-flag.stdout | 2 +- src/test/rustdoc-ui/run-directory.correct.stdout | 2 +- src/test/rustdoc-ui/run-directory.incorrect.stdout | 2 +- src/test/rustdoc-ui/test-no_std.stdout | 2 +- src/test/rustdoc-ui/test-type.stdout | 6 +++--- src/test/rustdoc-ui/unparseable-doc-test.stdout | 2 +- src/test/ui/test-attrs/test-filter-multiple.run.stdout | 4 ++-- src/test/ui/test-attrs/test-type.run.stdout | 4 ++-- src/test/ui/test-panic-abort-nocapture.run.stdout | 6 +++--- src/test/ui/test-panic-abort.run.stdout | 8 ++++---- src/test/ui/test-passed.run.stdout | 4 ++-- src/test/ui/test-thread-capture.run.stdout | 4 ++-- src/test/ui/test-thread-nocapture.run.stdout | 4 ++-- src/tools/compiletest/src/runtest.rs | 7 +++---- 26 files changed, 55 insertions(+), 46 deletions(-) diff --git a/library/test/src/formatters/pretty.rs b/library/test/src/formatters/pretty.rs index c1a0bb9f3e1e7..b3efb2c4437a7 100644 --- a/library/test/src/formatters/pretty.rs +++ b/library/test/src/formatters/pretty.rs @@ -169,7 +169,12 @@ impl PrettyFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - self.write_plain(&format!("test {} - {} ... ", name, desc.test_mode()))?; + let test_mode = desc.test_mode(); + if test_mode == "" { + self.write_plain(&format!("test {} ... ", name))?; + } else { + self.write_plain(&format!("test {} - {} ... ", name, test_mode))?; + } Ok(()) } diff --git a/library/test/src/formatters/terse.rs b/library/test/src/formatters/terse.rs index a9589829ad270..ce73f8d3bfbaf 100644 --- a/library/test/src/formatters/terse.rs +++ b/library/test/src/formatters/terse.rs @@ -158,7 +158,12 @@ impl TerseFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - self.write_plain(&format!("test {} - {} ... ", name, desc.test_mode()))?; + let test_mode = desc.test_mode(); + if test_mode == "" { + self.write_plain(&format!("test {} ... ", name))?; + } else { + self.write_plain(&format!("test {} - {} ... ", name, test_mode))?; + } Ok(()) } diff --git a/library/test/src/types.rs b/library/test/src/types.rs index 4cbdc7affc657..baf9908669b61 100644 --- a/library/test/src/types.rs +++ b/library/test/src/types.rs @@ -148,7 +148,7 @@ impl TestDesc { #[cfg(not(bootstrap))] pub fn test_mode(&self) -> &'static str { if self.ignore { - return &"ignore"; + return &""; } match self.should_panic { options::ShouldPanic::Yes | options::ShouldPanic::YesWithMessage(_) => { @@ -165,7 +165,7 @@ impl TestDesc { if self.no_run { return &"compile"; } - &"run" + &"" } #[cfg(bootstrap)] diff --git a/src/test/run-make-fulldeps/issue-22131/Makefile b/src/test/run-make-fulldeps/issue-22131/Makefile index 5f721ef313057..d76aaf5c146db 100644 --- a/src/test/run-make-fulldeps/issue-22131/Makefile +++ b/src/test/run-make-fulldeps/issue-22131/Makefile @@ -4,4 +4,4 @@ all: foo.rs $(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs $(RUSTDOC) --test --cfg 'feature="bar"' \ -L $(TMPDIR) foo.rs |\ - $(CGREP) 'foo.rs - foo (line 1) - run ... ok' + $(CGREP) 'foo.rs - foo (line 1) ... ok' diff --git a/src/test/run-make-fulldeps/test-harness/Makefile b/src/test/run-make-fulldeps/test-harness/Makefile index 1f3b112d6afe4..39477c07ced7c 100644 --- a/src/test/run-make-fulldeps/test-harness/Makefile +++ b/src/test/run-make-fulldeps/test-harness/Makefile @@ -3,6 +3,6 @@ all: # check that #[cfg_attr(..., ignore)] does the right thing. $(RUSTC) --test test-ignore-cfg.rs --cfg ignorecfg - $(call RUN,test-ignore-cfg) | $(CGREP) 'shouldnotignore - run ... ok' 'shouldignore - ignore ... ignored' + $(call RUN,test-ignore-cfg) | $(CGREP) 'shouldnotignore ... ok' 'shouldignore ... ignored' $(call RUN,test-ignore-cfg --quiet) | $(CGREP) -e "^i\.$$" $(call RUN,test-ignore-cfg --quiet) | $(CGREP) -v 'should' diff --git a/src/test/rustdoc-ui/cfg-test.stdout b/src/test/rustdoc-ui/cfg-test.stdout index 42d3fbb48dd86..2960ff8d3b473 100644 --- a/src/test/rustdoc-ui/cfg-test.stdout +++ b/src/test/rustdoc-ui/cfg-test.stdout @@ -1,7 +1,7 @@ running 2 tests -test $DIR/cfg-test.rs - Bar (line 27) - run ... ok -test $DIR/cfg-test.rs - Foo (line 19) - run ... ok +test $DIR/cfg-test.rs - Bar (line 27) ... ok +test $DIR/cfg-test.rs - Foo (line 19) ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doc-test-doctest-feature.stdout b/src/test/rustdoc-ui/doc-test-doctest-feature.stdout index cfcb60332f46b..d7de1f105228f 100644 --- a/src/test/rustdoc-ui/doc-test-doctest-feature.stdout +++ b/src/test/rustdoc-ui/doc-test-doctest-feature.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/doc-test-doctest-feature.rs - Foo (line 9) - run ... ok +test $DIR/doc-test-doctest-feature.rs - Foo (line 9) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout b/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout index 8d7f1ad21d1da..5b07fc4c87af5 100644 --- a/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout +++ b/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/doc-test-rustdoc-feature.rs - Foo (line 10) - run ... ok +test $DIR/doc-test-rustdoc-feature.rs - Foo (line 10) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/doctest-output.stdout b/src/test/rustdoc-ui/doctest-output.stdout index 7a07d273e2691..35b0e366fb5cc 100644 --- a/src/test/rustdoc-ui/doctest-output.stdout +++ b/src/test/rustdoc-ui/doctest-output.stdout @@ -1,8 +1,8 @@ running 3 tests -test $DIR/doctest-output.rs - (line 8) - run ... ok -test $DIR/doctest-output.rs - ExpandedStruct (line 24) - run ... ok -test $DIR/doctest-output.rs - foo::bar (line 18) - run ... ok +test $DIR/doctest-output.rs - (line 8) ... ok +test $DIR/doctest-output.rs - ExpandedStruct (line 24) ... ok +test $DIR/doctest-output.rs - foo::bar (line 18) ... ok test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index 7ba599ff11b90..6dfe648f8549e 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -1,7 +1,7 @@ running 2 tests -test $DIR/failed-doctest-output.rs - OtherStruct (line 22) - run ... FAILED -test $DIR/failed-doctest-output.rs - SomeStruct (line 12) - run ... FAILED +test $DIR/failed-doctest-output.rs - OtherStruct (line 22) ... FAILED +test $DIR/failed-doctest-output.rs - SomeStruct (line 12) ... FAILED failures: diff --git a/src/test/rustdoc-ui/failed-doctest-should-panic.stdout b/src/test/rustdoc-ui/failed-doctest-should-panic.stdout index 6bd21423e69eb..57a20092a5d6c 100644 --- a/src/test/rustdoc-ui/failed-doctest-should-panic.stdout +++ b/src/test/rustdoc-ui/failed-doctest-should-panic.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/failed-doctest-should-panic.rs - Foo (line 9) - run ... FAILED +test $DIR/failed-doctest-should-panic.rs - Foo (line 9) ... FAILED failures: diff --git a/src/test/rustdoc-ui/issue-81662-shortness.stdout b/src/test/rustdoc-ui/issue-81662-shortness.stdout index f9fdf7048d887..748113be3a26d 100644 --- a/src/test/rustdoc-ui/issue-81662-shortness.stdout +++ b/src/test/rustdoc-ui/issue-81662-shortness.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/issue-81662-shortness.rs - foo (line 6) - run ... FAILED +test $DIR/issue-81662-shortness.rs - foo (line 6) ... FAILED failures: diff --git a/src/test/rustdoc-ui/no-run-flag.stdout b/src/test/rustdoc-ui/no-run-flag.stdout index 22d927317b317..02f28aaf60da0 100644 --- a/src/test/rustdoc-ui/no-run-flag.stdout +++ b/src/test/rustdoc-ui/no-run-flag.stdout @@ -1,7 +1,7 @@ running 7 tests test $DIR/no-run-flag.rs - f (line 11) - compile ... ok -test $DIR/no-run-flag.rs - f (line 14) - ignore ... ignored +test $DIR/no-run-flag.rs - f (line 14) ... ignored test $DIR/no-run-flag.rs - f (line 17) - compile ... ok test $DIR/no-run-flag.rs - f (line 23) - compile fail ... ok test $DIR/no-run-flag.rs - f (line 28) - compile ... ok diff --git a/src/test/rustdoc-ui/run-directory.correct.stdout b/src/test/rustdoc-ui/run-directory.correct.stdout index 1bb84a868a414..e9b2754794a78 100644 --- a/src/test/rustdoc-ui/run-directory.correct.stdout +++ b/src/test/rustdoc-ui/run-directory.correct.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/run-directory.rs - foo (line 10) - run ... ok +test $DIR/run-directory.rs - foo (line 10) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/run-directory.incorrect.stdout b/src/test/rustdoc-ui/run-directory.incorrect.stdout index 7f6bba8fe471c..97a5dbc5c0cd1 100644 --- a/src/test/rustdoc-ui/run-directory.incorrect.stdout +++ b/src/test/rustdoc-ui/run-directory.incorrect.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/run-directory.rs - foo (line 19) - run ... ok +test $DIR/run-directory.rs - foo (line 19) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/test-no_std.stdout b/src/test/rustdoc-ui/test-no_std.stdout index 35d44fa6bbd05..8d5a30804c1e2 100644 --- a/src/test/rustdoc-ui/test-no_std.stdout +++ b/src/test/rustdoc-ui/test-no_std.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/test-no_std.rs - f (line 10) - run ... ok +test $DIR/test-no_std.rs - f (line 10) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/test-type.stdout b/src/test/rustdoc-ui/test-type.stdout index fb6c036a60817..a66fd240d34c4 100644 --- a/src/test/rustdoc-ui/test-type.stdout +++ b/src/test/rustdoc-ui/test-type.stdout @@ -1,10 +1,10 @@ running 5 tests -test $DIR/test-type.rs - f (line 12) - ignore ... ignored +test $DIR/test-type.rs - f (line 12) ... ignored test $DIR/test-type.rs - f (line 15) - compile ... ok test $DIR/test-type.rs - f (line 21) - compile fail ... ok -test $DIR/test-type.rs - f (line 6) - run ... ok -test $DIR/test-type.rs - f (line 9) - run ... ok +test $DIR/test-type.rs - f (line 6) ... ok +test $DIR/test-type.rs - f (line 9) ... ok test result: ok. 4 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/rustdoc-ui/unparseable-doc-test.stdout b/src/test/rustdoc-ui/unparseable-doc-test.stdout index 13526acfc479d..2641c66f25e77 100644 --- a/src/test/rustdoc-ui/unparseable-doc-test.stdout +++ b/src/test/rustdoc-ui/unparseable-doc-test.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/unparseable-doc-test.rs - foo (line 7) - run ... FAILED +test $DIR/unparseable-doc-test.rs - foo (line 7) ... FAILED failures: diff --git a/src/test/ui/test-attrs/test-filter-multiple.run.stdout b/src/test/ui/test-attrs/test-filter-multiple.run.stdout index 5d6d5cbd3c3f4..1aa684ed5073a 100644 --- a/src/test/ui/test-attrs/test-filter-multiple.run.stdout +++ b/src/test/ui/test-attrs/test-filter-multiple.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test test1 - run ... ok -test test2 - run ... ok +test test1 ... ok +test test2 ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in $TIME diff --git a/src/test/ui/test-attrs/test-type.run.stdout b/src/test/ui/test-attrs/test-type.run.stdout index 9f789526615d9..be2fd8ae68c36 100644 --- a/src/test/ui/test-attrs/test-type.run.stdout +++ b/src/test/ui/test-attrs/test-type.run.stdout @@ -1,7 +1,7 @@ running 3 tests -test test_no_run - ignore ... ignored -test test_ok - run ... ok +test test_no_run ... ignored +test test_ok ... ok test test_panic - should panic ... ok test result: ok. 2 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/ui/test-panic-abort-nocapture.run.stdout b/src/test/ui/test-panic-abort-nocapture.run.stdout index e335cf05153ba..8a91732a754ac 100644 --- a/src/test/ui/test-panic-abort-nocapture.run.stdout +++ b/src/test/ui/test-panic-abort-nocapture.run.stdout @@ -1,12 +1,12 @@ running 4 tests -test it_fails - run ... about to fail +test it_fails ... about to fail FAILED test it_panics - should panic ... about to panic ok -test it_works - run ... about to succeed +test it_works ... about to succeed ok -test it_writes_to_stdio - run ... hello, world +test it_writes_to_stdio ... hello, world testing123 ok diff --git a/src/test/ui/test-panic-abort.run.stdout b/src/test/ui/test-panic-abort.run.stdout index 0d9de10c98189..f608a8cdc5569 100644 --- a/src/test/ui/test-panic-abort.run.stdout +++ b/src/test/ui/test-panic-abort.run.stdout @@ -1,10 +1,10 @@ running 5 tests -test it_exits - run ... FAILED -test it_fails - run ... FAILED +test it_exits ... FAILED +test it_fails ... FAILED test it_panics - should panic ... ok -test it_works - run ... ok -test no_residual_environment - run ... ok +test it_works ... ok +test no_residual_environment ... ok failures: diff --git a/src/test/ui/test-passed.run.stdout b/src/test/ui/test-passed.run.stdout index 995643a62c88f..17f70d607494e 100644 --- a/src/test/ui/test-passed.run.stdout +++ b/src/test/ui/test-passed.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test it_works - run ... ok -test it_works_too - run ... ok +test it_works ... ok +test it_works_too ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/src/test/ui/test-thread-capture.run.stdout b/src/test/ui/test-thread-capture.run.stdout index ce9ec63b526c9..487cfb55eb473 100644 --- a/src/test/ui/test-thread-capture.run.stdout +++ b/src/test/ui/test-thread-capture.run.stdout @@ -1,7 +1,7 @@ running 2 tests -test thready_fail - run ... FAILED -test thready_pass - run ... ok +test thready_fail ... FAILED +test thready_pass ... ok failures: diff --git a/src/test/ui/test-thread-nocapture.run.stdout b/src/test/ui/test-thread-nocapture.run.stdout index bd1971ab7d310..9d2da50826c25 100644 --- a/src/test/ui/test-thread-nocapture.run.stdout +++ b/src/test/ui/test-thread-nocapture.run.stdout @@ -1,11 +1,11 @@ running 2 tests -test thready_fail - run ... fee +test thready_fail ... fee fie foe fum FAILED -test thready_pass - run ... fee +test thready_pass ... fee fie foe fum diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 0898e9ef2f630..18c40a037c57c 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2637,12 +2637,11 @@ impl<'test> TestCx<'test> { let mut tested = 0; for _ in res.stdout.split('\n').filter(|s| s.starts_with("test ")).inspect(|s| { - let tmp: Vec<&str> = s.split(" - ").collect(); - if tmp.len() == 3 { - let path = tmp[0].rsplit("test ").next().unwrap(); + if let Some((left, right)) = s.split_once(" - ") { + let path = left.rsplit("test ").next().unwrap(); if let Some(ref mut v) = files.get_mut(&path.replace('\\', "/")) { tested += 1; - let mut iter = tmp[1].split("(line "); + let mut iter = right.split("(line "); iter.next(); let line = iter .next() From 6de13c3ffc969ceac87f2a8466c5cd850288721c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Tue, 18 May 2021 18:17:36 +0200 Subject: [PATCH 06/14] change based on review --- library/test/src/formatters/pretty.rs | 7 +++---- library/test/src/formatters/terse.rs | 7 +++---- library/test/src/types.rs | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/library/test/src/formatters/pretty.rs b/library/test/src/formatters/pretty.rs index b3efb2c4437a7..e17fc08a9ae99 100644 --- a/library/test/src/formatters/pretty.rs +++ b/library/test/src/formatters/pretty.rs @@ -169,11 +169,10 @@ impl PrettyFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - let test_mode = desc.test_mode(); - if test_mode == "" { - self.write_plain(&format!("test {} ... ", name))?; - } else { + if let Some(test_mode) = desc.test_mode() { self.write_plain(&format!("test {} - {} ... ", name, test_mode))?; + } else { + self.write_plain(&format!("test {} ... ", name))?; } Ok(()) diff --git a/library/test/src/formatters/terse.rs b/library/test/src/formatters/terse.rs index ce73f8d3bfbaf..a2c223c494c29 100644 --- a/library/test/src/formatters/terse.rs +++ b/library/test/src/formatters/terse.rs @@ -158,11 +158,10 @@ impl TerseFormatter { fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> { let name = desc.padded_name(self.max_name_len, desc.name.padding()); - let test_mode = desc.test_mode(); - if test_mode == "" { - self.write_plain(&format!("test {} ... ", name))?; - } else { + if let Some(test_mode) = desc.test_mode() { self.write_plain(&format!("test {} - {} ... ", name, test_mode))?; + } else { + self.write_plain(&format!("test {} ... ", name))?; } Ok(()) diff --git a/library/test/src/types.rs b/library/test/src/types.rs index baf9908669b61..63907c71ea7cc 100644 --- a/library/test/src/types.rs +++ b/library/test/src/types.rs @@ -145,32 +145,34 @@ impl TestDesc { } } + /// Returns None for ignored test or that that are just run, otherwise give a description of the type of test. + /// Descriptions include "should panic", "compile fail" and "compile". #[cfg(not(bootstrap))] - pub fn test_mode(&self) -> &'static str { + pub fn test_mode(&self) -> Option<&'static str> { if self.ignore { - return &""; + return None; } match self.should_panic { options::ShouldPanic::Yes | options::ShouldPanic::YesWithMessage(_) => { - return &"should panic"; + return Some("should panic"); } options::ShouldPanic::No => {} } if self.allow_fail { - return &"allow fail"; + return Some("allow fail"); } if self.compile_fail { - return &"compile fail"; + return Some("compile fail"); } if self.no_run { - return &"compile"; + return Some("compile"); } - &"" + None } #[cfg(bootstrap)] - pub fn test_mode(&self) -> &'static str { - &"" + pub fn test_mode(&self) -> Option<&'static str> { + None } } From 01d4d46f66929122cc890279cde4765df7a0a90f Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Sun, 30 May 2021 23:16:45 +0600 Subject: [PATCH 07/14] Replace IntoIter::new with IntoIterator::into_iter in std --- .../src/collections/vec_deque/pair_slices.rs | 3 +- library/core/src/array/mod.rs | 4 +- library/core/tests/array.rs | 44 +++++++++---------- .../array-impls/into-iter-impls-length-32.rs | 14 +++--- .../array-impls/into-iter-impls-length-33.rs | 14 +++--- 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/pair_slices.rs b/library/alloc/src/collections/vec_deque/pair_slices.rs index 812765d0b0ded..7b87090fb0713 100644 --- a/library/alloc/src/collections/vec_deque/pair_slices.rs +++ b/library/alloc/src/collections/vec_deque/pair_slices.rs @@ -1,4 +1,3 @@ -use core::array; use core::cmp::{self}; use core::mem::replace; @@ -37,7 +36,7 @@ impl<'a, 'b, T> PairSlices<'a, 'b, T> { } pub fn remainder(self) -> impl Iterator { - array::IntoIter::new([self.b0, self.b1]) + IntoIterator::into_iter([self.b0, self.b1]) } } diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index e25d006d213c7..37af3557fdd51 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -416,7 +416,7 @@ impl [T; N] { { // SAFETY: we know for certain that this iterator will yield exactly `N` // items. - unsafe { collect_into_array_unchecked(&mut IntoIter::new(self).map(f)) } + unsafe { collect_into_array_unchecked(&mut IntoIterator::into_iter(self).map(f)) } } /// 'Zips up' two arrays into a single array of pairs. @@ -437,7 +437,7 @@ impl [T; N] { /// ``` #[unstable(feature = "array_zip", issue = "80094")] pub fn zip(self, rhs: [U; N]) -> [(T, U); N] { - let mut iter = IntoIter::new(self).zip(IntoIter::new(rhs)); + let mut iter = IntoIterator::into_iter(self).zip(rhs); // SAFETY: we know for certain that this iterator will yield exactly `N` // items. diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index ce7480ce2ee89..42f44c23fe783 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -41,14 +41,14 @@ fn array_try_from() { #[test] fn iterator_collect() { let arr = [0, 1, 2, 5, 9]; - let v: Vec<_> = IntoIter::new(arr.clone()).collect(); + let v: Vec<_> = IntoIterator::into_iter(arr.clone()).collect(); assert_eq!(&arr[..], &v[..]); } #[test] fn iterator_rev_collect() { let arr = [0, 1, 2, 5, 9]; - let v: Vec<_> = IntoIter::new(arr.clone()).rev().collect(); + let v: Vec<_> = IntoIterator::into_iter(arr.clone()).rev().collect(); assert_eq!(&v[..], &[9, 5, 2, 1, 0]); } @@ -56,11 +56,11 @@ fn iterator_rev_collect() { fn iterator_nth() { let v = [0, 1, 2, 3, 4]; for i in 0..v.len() { - assert_eq!(IntoIter::new(v.clone()).nth(i).unwrap(), v[i]); + assert_eq!(IntoIterator::into_iter(v.clone()).nth(i).unwrap(), v[i]); } - assert_eq!(IntoIter::new(v.clone()).nth(v.len()), None); + assert_eq!(IntoIterator::into_iter(v.clone()).nth(v.len()), None); - let mut iter = IntoIter::new(v); + let mut iter = IntoIterator::into_iter(v); assert_eq!(iter.nth(2).unwrap(), v[2]); assert_eq!(iter.nth(1).unwrap(), v[4]); } @@ -68,17 +68,17 @@ fn iterator_nth() { #[test] fn iterator_last() { let v = [0, 1, 2, 3, 4]; - assert_eq!(IntoIter::new(v).last().unwrap(), 4); - assert_eq!(IntoIter::new([0]).last().unwrap(), 0); + assert_eq!(IntoIterator::into_iter(v).last().unwrap(), 4); + assert_eq!(IntoIterator::into_iter([0]).last().unwrap(), 0); - let mut it = IntoIter::new([0, 9, 2, 4]); + let mut it = IntoIterator::into_iter([0, 9, 2, 4]); assert_eq!(it.next_back(), Some(4)); assert_eq!(it.last(), Some(2)); } #[test] fn iterator_clone() { - let mut it = IntoIter::new([0, 2, 4, 6, 8]); + let mut it = IntoIterator::into_iter([0, 2, 4, 6, 8]); assert_eq!(it.next(), Some(0)); assert_eq!(it.next_back(), Some(8)); let mut clone = it.clone(); @@ -92,7 +92,7 @@ fn iterator_clone() { #[test] fn iterator_fused() { - let mut it = IntoIter::new([0, 9, 2]); + let mut it = IntoIterator::into_iter([0, 9, 2]); assert_eq!(it.next(), Some(0)); assert_eq!(it.next(), Some(9)); assert_eq!(it.next(), Some(2)); @@ -105,7 +105,7 @@ fn iterator_fused() { #[test] fn iterator_len() { - let mut it = IntoIter::new([0, 1, 2, 5, 9]); + let mut it = IntoIterator::into_iter([0, 1, 2, 5, 9]); assert_eq!(it.size_hint(), (5, Some(5))); assert_eq!(it.len(), 5); assert_eq!(it.is_empty(), false); @@ -121,7 +121,7 @@ fn iterator_len() { assert_eq!(it.is_empty(), false); // Empty - let it = IntoIter::new([] as [String; 0]); + let it = IntoIterator::into_iter([] as [String; 0]); assert_eq!(it.size_hint(), (0, Some(0))); assert_eq!(it.len(), 0); assert_eq!(it.is_empty(), true); @@ -130,9 +130,9 @@ fn iterator_len() { #[test] fn iterator_count() { let v = [0, 1, 2, 3, 4]; - assert_eq!(IntoIter::new(v.clone()).count(), 5); + assert_eq!(IntoIterator::into_iter(v.clone()).count(), 5); - let mut iter2 = IntoIter::new(v); + let mut iter2 = IntoIterator::into_iter(v); iter2.next(); iter2.next(); assert_eq!(iter2.count(), 3); @@ -140,13 +140,13 @@ fn iterator_count() { #[test] fn iterator_flat_map() { - assert!((0..5).flat_map(|i| IntoIter::new([2 * i, 2 * i + 1])).eq(0..10)); + assert!((0..5).flat_map(|i| IntoIterator::into_iter([2 * i, 2 * i + 1])).eq(0..10)); } #[test] fn iterator_debug() { let arr = [0, 1, 2, 5, 9]; - assert_eq!(format!("{:?}", IntoIter::new(arr)), "IntoIter([0, 1, 2, 5, 9])",); + assert_eq!(format!("{:?}", IntoIterator::into_iter(arr)), "IntoIter([0, 1, 2, 5, 9])",); } #[test] @@ -176,14 +176,14 @@ fn iterator_drops() { // Simple: drop new iterator. let i = Cell::new(0); { - IntoIter::new(five(&i)); + IntoIterator::into_iter(five(&i)); } assert_eq!(i.get(), 5); // Call `next()` once. let i = Cell::new(0); { - let mut iter = IntoIter::new(five(&i)); + let mut iter = IntoIterator::into_iter(five(&i)); let _x = iter.next(); assert_eq!(i.get(), 0); assert_eq!(iter.count(), 4); @@ -194,7 +194,7 @@ fn iterator_drops() { // Check `clone` and calling `next`/`next_back`. let i = Cell::new(0); { - let mut iter = IntoIter::new(five(&i)); + let mut iter = IntoIterator::into_iter(five(&i)); iter.next(); assert_eq!(i.get(), 1); iter.next_back(); @@ -217,7 +217,7 @@ fn iterator_drops() { // Check via `nth`. let i = Cell::new(0); { - let mut iter = IntoIter::new(five(&i)); + let mut iter = IntoIterator::into_iter(five(&i)); let _x = iter.nth(2); assert_eq!(i.get(), 2); let _y = iter.last(); @@ -227,13 +227,13 @@ fn iterator_drops() { // Check every element. let i = Cell::new(0); - for (index, _x) in IntoIter::new(five(&i)).enumerate() { + for (index, _x) in IntoIterator::into_iter(five(&i)).enumerate() { assert_eq!(i.get(), index); } assert_eq!(i.get(), 5); let i = Cell::new(0); - for (index, _x) in IntoIter::new(five(&i)).rev().enumerate() { + for (index, _x) in IntoIterator::into_iter(five(&i)).rev().enumerate() { assert_eq!(i.get(), index); } assert_eq!(i.get(), 5); diff --git a/src/test/ui/const-generics/array-impls/into-iter-impls-length-32.rs b/src/test/ui/const-generics/array-impls/into-iter-impls-length-32.rs index 6ba1b2813a177..457e5ae60494a 100644 --- a/src/test/ui/const-generics/array-impls/into-iter-impls-length-32.rs +++ b/src/test/ui/const-generics/array-impls/into-iter-impls-length-32.rs @@ -9,31 +9,31 @@ use std::{ }; pub fn yes_iterator() -> impl Iterator { - IntoIter::new([0i32; 32]) + IntoIterator::into_iter([0i32; 32]) } pub fn yes_double_ended_iterator() -> impl DoubleEndedIterator { - IntoIter::new([0i32; 32]) + IntoIterator::into_iter([0i32; 32]) } pub fn yes_exact_size_iterator() -> impl ExactSizeIterator { - IntoIter::new([0i32; 32]) + IntoIterator::into_iter([0i32; 32]) } pub fn yes_fused_iterator() -> impl FusedIterator { - IntoIter::new([0i32; 32]) + IntoIterator::into_iter([0i32; 32]) } pub fn yes_trusted_len() -> impl TrustedLen { - IntoIter::new([0i32; 32]) + IntoIterator::into_iter([0i32; 32]) } pub fn yes_clone() -> impl Clone { - IntoIter::new([0i32; 32]) + IntoIterator::into_iter([0i32; 32]) } pub fn yes_debug() -> impl Debug { - IntoIter::new([0i32; 32]) + IntoIterator::into_iter([0i32; 32]) } diff --git a/src/test/ui/const-generics/array-impls/into-iter-impls-length-33.rs b/src/test/ui/const-generics/array-impls/into-iter-impls-length-33.rs index deafde2912bb7..4f343f3f97ea4 100644 --- a/src/test/ui/const-generics/array-impls/into-iter-impls-length-33.rs +++ b/src/test/ui/const-generics/array-impls/into-iter-impls-length-33.rs @@ -9,31 +9,31 @@ use std::{ }; pub fn yes_iterator() -> impl Iterator { - IntoIter::new([0i32; 33]) + IntoIterator::into_iter([0i32; 33]) } pub fn yes_double_ended_iterator() -> impl DoubleEndedIterator { - IntoIter::new([0i32; 33]) + IntoIterator::into_iter([0i32; 33]) } pub fn yes_exact_size_iterator() -> impl ExactSizeIterator { - IntoIter::new([0i32; 33]) + IntoIterator::into_iter([0i32; 33]) } pub fn yes_fused_iterator() -> impl FusedIterator { - IntoIter::new([0i32; 33]) + IntoIterator::into_iter([0i32; 33]) } pub fn yes_trusted_len() -> impl TrustedLen { - IntoIter::new([0i32; 33]) + IntoIterator::into_iter([0i32; 33]) } pub fn yes_clone() -> impl Clone { - IntoIter::new([0i32; 33]) + IntoIterator::into_iter([0i32; 33]) } pub fn yes_debug() -> impl Debug { - IntoIter::new([0i32; 33]) + IntoIterator::into_iter([0i32; 33]) } From 507d97b26efc002129e5ba084f4361d7fde636ff Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Wed, 2 Jun 2021 16:06:34 +0600 Subject: [PATCH 08/14] Update expressions where we can use array's IntoIterator implementation --- library/alloc/benches/vec.rs | 10 ++-------- library/alloc/src/vec/mod.rs | 8 ++++---- library/alloc/src/vec/splice.rs | 2 +- library/alloc/tests/vec.rs | 10 +++++----- library/core/src/char/methods.rs | 4 ++-- library/core/tests/array.rs | 2 +- library/core/tests/iter/adapters/zip.rs | 4 +--- 7 files changed, 16 insertions(+), 24 deletions(-) diff --git a/library/alloc/benches/vec.rs b/library/alloc/benches/vec.rs index c9bdcaa78f391..91eec10d57593 100644 --- a/library/alloc/benches/vec.rs +++ b/library/alloc/benches/vec.rs @@ -551,19 +551,13 @@ const LEN: usize = 16384; #[bench] fn bench_chain_collect(b: &mut Bencher) { let data = black_box([0; LEN]); - b.iter(|| data.iter().cloned().chain([1].iter().cloned()).collect::>()); + b.iter(|| data.iter().cloned().chain([1]).collect::>()); } #[bench] fn bench_chain_chain_collect(b: &mut Bencher) { let data = black_box([0; LEN]); - b.iter(|| { - data.iter() - .cloned() - .chain([1].iter().cloned()) - .chain([2].iter().cloned()) - .collect::>() - }); + b.iter(|| data.iter().cloned().chain([1]).chain([2]).collect::>()); } #[bench] diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 105c60e7bf085..4a1d564e2ab87 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -921,7 +921,7 @@ impl Vec { /// /// ``` /// let mut vec = Vec::with_capacity(10); - /// vec.extend([1, 2, 3].iter().cloned()); + /// vec.extend([1, 2, 3]); /// assert_eq!(vec.capacity(), 10); /// vec.shrink_to_fit(); /// assert!(vec.capacity() >= 3); @@ -950,7 +950,7 @@ impl Vec { /// ``` /// #![feature(shrink_to)] /// let mut vec = Vec::with_capacity(10); - /// vec.extend([1, 2, 3].iter().cloned()); + /// vec.extend([1, 2, 3]); /// assert_eq!(vec.capacity(), 10); /// vec.shrink_to(4); /// assert!(vec.capacity() >= 4); @@ -984,7 +984,7 @@ impl Vec { /// /// ``` /// let mut vec = Vec::with_capacity(10); - /// vec.extend([1, 2, 3].iter().cloned()); + /// vec.extend([1, 2, 3]); /// /// assert_eq!(vec.capacity(), 10); /// let slice = vec.into_boxed_slice(); @@ -2586,7 +2586,7 @@ impl Vec { /// ``` /// let mut v = vec![1, 2, 3]; /// let new = [7, 8]; - /// let u: Vec<_> = v.splice(..2, new.iter().cloned()).collect(); + /// let u: Vec<_> = v.splice(..2, new).collect(); /// assert_eq!(v, &[7, 8, 3]); /// assert_eq!(u, &[1, 2]); /// ``` diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 0a27b5b62ecf5..bad765c7f51fa 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -14,7 +14,7 @@ use super::{Drain, Vec}; /// ``` /// let mut v = vec![0, 1, 2]; /// let new = [7, 8]; -/// let iter: std::vec::Splice<_> = v.splice(1.., new.iter().cloned()); +/// let iter: std::vec::Splice<_> = v.splice(1.., new); /// ``` #[derive(Debug)] #[stable(feature = "vec_splice", since = "1.21.0")] diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 36c81b4970973..c203cdafecb03 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -793,7 +793,7 @@ fn test_drain_leak() { fn test_splice() { let mut v = vec![1, 2, 3, 4, 5]; let a = [10, 11, 12]; - v.splice(2..4, a.iter().cloned()); + v.splice(2..4, a); assert_eq!(v, &[1, 2, 10, 11, 12, 5]); v.splice(1..3, Some(20)); assert_eq!(v, &[1, 20, 11, 12, 5]); @@ -803,7 +803,7 @@ fn test_splice() { fn test_splice_inclusive_range() { let mut v = vec![1, 2, 3, 4, 5]; let a = [10, 11, 12]; - let t1: Vec<_> = v.splice(2..=3, a.iter().cloned()).collect(); + let t1: Vec<_> = v.splice(2..=3, a).collect(); assert_eq!(v, &[1, 2, 10, 11, 12, 5]); assert_eq!(t1, &[3, 4]); let t2: Vec<_> = v.splice(1..=2, Some(20)).collect(); @@ -816,7 +816,7 @@ fn test_splice_inclusive_range() { fn test_splice_out_of_bounds() { let mut v = vec![1, 2, 3, 4, 5]; let a = [10, 11, 12]; - v.splice(5..6, a.iter().cloned()); + v.splice(5..6, a); } #[test] @@ -824,7 +824,7 @@ fn test_splice_out_of_bounds() { fn test_splice_inclusive_out_of_bounds() { let mut v = vec![1, 2, 3, 4, 5]; let a = [10, 11, 12]; - v.splice(5..=5, a.iter().cloned()); + v.splice(5..=5, a); } #[test] @@ -848,7 +848,7 @@ fn test_splice_unbounded() { fn test_splice_forget() { let mut v = vec![1, 2, 3, 4, 5]; let a = [10, 11, 12]; - std::mem::forget(v.splice(2..4, a.iter().cloned())); + std::mem::forget(v.splice(2..4, a)); assert_eq!(v, &[1, 2]); } diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index dcab2cd2d9db1..2da3d6a72fb6f 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -58,7 +58,7 @@ impl char { /// ]; /// /// assert_eq!( - /// decode_utf16(v.iter().cloned()) + /// decode_utf16(v) /// .map(|r| r.map_err(|e| e.unpaired_surrogate())) /// .collect::>(), /// vec![ @@ -82,7 +82,7 @@ impl char { /// ]; /// /// assert_eq!( - /// decode_utf16(v.iter().cloned()) + /// decode_utf16(v) /// .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER)) /// .collect::(), /// "𝄞mus�ic�" diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index 42f44c23fe783..0ae625bdb68c6 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -1,4 +1,4 @@ -use core::array::{self, IntoIter}; +use core::array; use core::convert::TryFrom; #[test] diff --git a/library/core/tests/iter/adapters/zip.rs b/library/core/tests/iter/adapters/zip.rs index 000c15f72c886..797bfd957f906 100644 --- a/library/core/tests/iter/adapters/zip.rs +++ b/library/core/tests/iter/adapters/zip.rs @@ -236,9 +236,7 @@ fn test_zip_trusted_random_access_composition() { fn test_double_ended_zip() { let xs = [1, 2, 3, 4, 5, 6]; let ys = [1, 2, 3, 7]; - let a = xs.iter().cloned(); - let b = ys.iter().cloned(); - let mut it = a.zip(b); + let mut it = xs.iter().cloned().zip(ys); assert_eq!(it.next(), Some((1, 1))); assert_eq!(it.next(), Some((2, 2))); assert_eq!(it.next_back(), Some((4, 7))); From f4080fca627d36ffda16410cb957348119ae64ea Mon Sep 17 00:00:00 2001 From: LingMan Date: Sat, 5 Jun 2021 18:12:47 +0200 Subject: [PATCH 09/14] Drop an `if let` that will always succeed We've already checked that `proj_base == []` in the line above and renaming `place_local` to `local` doesn't gain us anything. --- .../src/transform/check_consts/validation.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs index ac3420ad33950..4fbd27c89d9c8 100644 --- a/compiler/rustc_mir/src/transform/check_consts/validation.rs +++ b/compiler/rustc_mir/src/transform/check_consts/validation.rs @@ -729,13 +729,11 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty; if let ty::RawPtr(_) = base_ty.kind() { if proj_base.is_empty() { - if let (local, []) = (place_local, proj_base) { - let decl = &self.body.local_decls[local]; - if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info { - let span = decl.source_info.span; - self.check_static(def_id, span); - return; - } + let decl = &self.body.local_decls[place_local]; + if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info { + let span = decl.source_info.span; + self.check_static(def_id, span); + return; } } self.check_op(ops::RawPtrDeref); From 894b42c8616f352eacf54bc830c01e33b406fb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 4 Jun 2021 00:00:00 +0000 Subject: [PATCH 10/14] Disallow non-monomorphic calls to `needs_drop` in interpreter otherwise evaluation could change after further substitutions. --- .../rustc_mir/src/interpret/intrinsics.rs | 5 ++++- .../ui/consts/const-needs_drop-monomorphic.rs | 17 ++++++++++++++++ .../const-needs_drop-monomorphic.stderr | 20 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/const-needs_drop-monomorphic.rs create mode 100644 src/test/ui/consts/const-needs_drop-monomorphic.stderr diff --git a/compiler/rustc_mir/src/interpret/intrinsics.rs b/compiler/rustc_mir/src/interpret/intrinsics.rs index 99622fb310aaf..cdd1edbf2866e 100644 --- a/compiler/rustc_mir/src/interpret/intrinsics.rs +++ b/compiler/rustc_mir/src/interpret/intrinsics.rs @@ -56,7 +56,10 @@ crate fn eval_nullary_intrinsic<'tcx>( let alloc = type_name::alloc_type_name(tcx, tp_ty); ConstValue::Slice { data: alloc, start: 0, end: alloc.len() } } - sym::needs_drop => ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env)), + sym::needs_drop => { + ensure_monomorphic_enough(tcx, tp_ty)?; + ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env)) + } sym::min_align_of | sym::pref_align_of => { let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?; let n = match name { diff --git a/src/test/ui/consts/const-needs_drop-monomorphic.rs b/src/test/ui/consts/const-needs_drop-monomorphic.rs new file mode 100644 index 0000000000000..9f66e3cfa23c0 --- /dev/null +++ b/src/test/ui/consts/const-needs_drop-monomorphic.rs @@ -0,0 +1,17 @@ +// Check that evaluation of needs_drop fails when T is not monomorphic. +#![feature(const_generics)] +#![allow(const_evaluatable_unchecked)] +#![allow(incomplete_features)] + +struct Bool {} +impl Bool { + fn assert() {} +} +fn f() { + Bool::<{ std::mem::needs_drop::() }>::assert(); + //~^ ERROR no function or associated item named `assert` found + //~| ERROR constant expression depends on a generic parameter +} +fn main() { + f::(); +} diff --git a/src/test/ui/consts/const-needs_drop-monomorphic.stderr b/src/test/ui/consts/const-needs_drop-monomorphic.stderr new file mode 100644 index 0000000000000..0770d06e15be8 --- /dev/null +++ b/src/test/ui/consts/const-needs_drop-monomorphic.stderr @@ -0,0 +1,20 @@ +error[E0599]: no function or associated item named `assert` found for struct `Bool<{ std::mem::needs_drop::() }>` in the current scope + --> $DIR/const-needs_drop-monomorphic.rs:11:46 + | +LL | struct Bool {} + | -------------------------- function or associated item `assert` not found for this +... +LL | Bool::<{ std::mem::needs_drop::() }>::assert(); + | ^^^^^^ function or associated item cannot be called on `Bool<{ std::mem::needs_drop::() }>` due to unsatisfied trait bounds + +error: constant expression depends on a generic parameter + --> $DIR/const-needs_drop-monomorphic.rs:11:5 + | +LL | Bool::<{ std::mem::needs_drop::() }>::assert(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this may fail depending on what value the parameter takes + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0599`. From 07a03b0a58438778336f525f5e567e44500704c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sat, 5 Jun 2021 00:00:00 +0000 Subject: [PATCH 11/14] Explain that `ensure_monomorphic_enough` omission is intentional --- compiler/rustc_mir/src/interpret/intrinsics.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_mir/src/interpret/intrinsics.rs b/compiler/rustc_mir/src/interpret/intrinsics.rs index cdd1edbf2866e..4e4166dad50e2 100644 --- a/compiler/rustc_mir/src/interpret/intrinsics.rs +++ b/compiler/rustc_mir/src/interpret/intrinsics.rs @@ -61,6 +61,7 @@ crate fn eval_nullary_intrinsic<'tcx>( ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env)) } sym::min_align_of | sym::pref_align_of => { + // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough. let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?; let n = match name { sym::pref_align_of => layout.align.pref.bytes(), @@ -74,6 +75,7 @@ crate fn eval_nullary_intrinsic<'tcx>( ConstValue::from_u64(tcx.type_id_hash(tp_ty)) } sym::variant_count => match tp_ty.kind() { + // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough. ty::Adt(ref adt, _) => ConstValue::from_machine_usize(adt.variants.len() as u64, &tcx), ty::Projection(_) | ty::Opaque(_, _) From e1180f521f8f2d01745b50b228f7b426cb4565dc Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 3 Jun 2021 20:07:25 +0200 Subject: [PATCH 12/14] Escape content attribute value --- src/librustdoc/html/layout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 7309a1da23038..c3843e7213560 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -161,7 +161,7 @@ crate fn render( } }, title = page.title, - description = page.description, + description = Escape(page.description), keywords = page.keywords, favicon = if layout.favicon.is_empty() { format!( From 8c9200d045c0d7b41a02a1c67ffb0ec7be379c65 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 3 Jun 2021 20:07:54 +0200 Subject: [PATCH 13/14] Add missing backslash in HTML layout string --- src/librustdoc/html/layout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index c3843e7213560..d2d1757b9009a 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -105,7 +105,7 @@ crate fn render( placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \ type=\"search\">\ \ - + \ \ Date: Thu, 3 Jun 2021 20:16:47 +0200 Subject: [PATCH 14/14] Fix invalid ID value in all.html file --- src/librustdoc/html/render/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 10f5184e39a67..4b6faefc2fb07 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -322,7 +322,13 @@ impl AllTypes { if !e.is_empty() { let mut e: Vec<&ItemEntry> = e.iter().collect(); e.sort(); - write!(f, "

{}

    ", title, title, class); + write!( + f, + "

    {}

      ", + title.replace(' ', "-"), // IDs cannot contain whitespaces. + title, + class + ); for s in e.iter() { write!(f, "
    • {}
    • ", s.print()); @@ -346,7 +352,7 @@ impl AllTypes { ", ); // Note: print_entries does not escape the title, because we know the current set of titles - // don't require escaping. + // doesn't require escaping. print_entries(f, &self.structs, "Structs", "structs"); print_entries(f, &self.enums, "Enums", "enums"); print_entries(f, &self.unions, "Unions", "unions");