diff options
| author | dylan_DPC <dylan.dpc@gmail.com> | 2018-06-02 17:27:37 +0530 |
|---|---|---|
| committer | dylan_DPC <dylan.dpc@gmail.com> | 2018-06-02 17:27:37 +0530 |
| commit | b78457f0fbe15c21dc28efaef8146a0ff9d58059 (patch) | |
| tree | 17894e31c955fd76742a5a6c54aca7580da1b49a /src/libsyntax | |
| parent | 2954cb511922173b714aa930f6bd1721d40fa02d (diff) | |
| download | rust-b78457f0fbe15c21dc28efaef8146a0ff9d58059.tar.gz rust-b78457f0fbe15c21dc28efaef8146a0ff9d58059.zip | |
Stabilize unit tests with non-`()` return type
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 38 |
2 files changed, 10 insertions, 34 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9b84713b0f9..ecda2b077e1 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -398,9 +398,6 @@ declare_features! ( // `foo.rs` as an alternative to `foo/mod.rs` (active, non_modrs_mods, "1.24.0", Some(44660), Some(Edition::Edition2018)), - // Termination trait in tests (RFC 1937) - (active, termination_trait_test, "1.24.0", Some(48854), Some(Edition::Edition2018)), - // `extern` in paths (active, extern_in_paths, "1.23.0", Some(44660), None), @@ -475,6 +472,9 @@ declare_features! ( // 'a: { break 'a; } (active, label_break_value, "1.28.0", Some(48594), None), + + // Termination trait in tests (RFC 1937) + (accepted, termination_trait_test, "1.28.0", Some(48854), Some(Edition::Edition2018)), ); declare_features! ( diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index e63a3d47a82..5506f408cd2 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -351,15 +351,15 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool { return No(BadTestSignature::NoArgumentsAllowed); } - match (has_output, cx.features.termination_trait_test, has_should_panic_attr) { - (true, true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs), - (true, true, false) => if generics.is_parameterized() { + match (has_output, has_should_panic_attr) { + (true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs), + (true, false) => if generics.is_parameterized() { No(BadTestSignature::WrongTypeSignature) } else { Yes }, - (true, false, _) => No(BadTestSignature::WrongTypeSignature), - (false, _, _) => Yes + (true, _) => No(BadTestSignature::WrongTypeSignature), + (false, _) => Yes } } _ => No(BadTestSignature::NotEvenAFunction), @@ -398,28 +398,9 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool { fn has_bench_signature(cx: &TestCtxt, i: &ast::Item) -> bool { match i.node { ast::ItemKind::Fn(ref decl, _, _, _, ref generics, _) => { - let input_cnt = decl.inputs.len(); - - // If the termination trait is active, the compiler will check that the output - // type implements the `Termination` trait as `libtest` enforces that. - let output_matches = if cx.features.termination_trait_test { - true - } else { - let no_output = match decl.output { - ast::FunctionRetTy::Default(..) => true, - ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => true, - _ => false - }; - let tparm_cnt = generics.params.iter() - .filter(|param| param.is_type_param()) - .count(); - - no_output && tparm_cnt == 0 - }; - // NB: inadequate check, but we're running // well before resolve, can't get too deep. - input_cnt == 1 && output_matches + decl.inputs.len() == 1 } _ => false } @@ -430,13 +411,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool { if has_bench_attr && !has_bench_signature { let diag = cx.span_diagnostic; - if cx.features.termination_trait_test { - diag.span_err(i.span, "functions used as benches must have signature \ + diag.span_err(i.span, "functions used as benches must have signature \ `fn(&mut Bencher) -> impl Termination`"); - } else { - diag.span_err(i.span, "functions used as benches must have signature \ - `fn(&mut Bencher) -> ()`"); - } } has_bench_attr && has_bench_signature |
