Skip to content

Commit b78457f

Browse files
committed
Stabilize unit tests with non-() return type
1 parent 2954cb5 commit b78457f

File tree

6 files changed

+10
-60
lines changed

6 files changed

+10
-60
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ declare_features! (
398398
// `foo.rs` as an alternative to `foo/mod.rs`
399399
(active, non_modrs_mods, "1.24.0", Some(44660), Some(Edition::Edition2018)),
400400

401-
// Termination trait in tests (RFC 1937)
402-
(active, termination_trait_test, "1.24.0", Some(48854), Some(Edition::Edition2018)),
403-
404401
// `extern` in paths
405402
(active, extern_in_paths, "1.23.0", Some(44660), None),
406403

@@ -475,6 +472,9 @@ declare_features! (
475472

476473
// 'a: { break 'a; }
477474
(active, label_break_value, "1.28.0", Some(48594), None),
475+
476+
// Termination trait in tests (RFC 1937)
477+
(accepted, termination_trait_test, "1.28.0", Some(48854), Some(Edition::Edition2018)),
478478
);
479479

480480
declare_features! (

src/libsyntax/test.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
351351
return No(BadTestSignature::NoArgumentsAllowed);
352352
}
353353

354-
match (has_output, cx.features.termination_trait_test, has_should_panic_attr) {
355-
(true, true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs),
356-
(true, true, false) => if generics.is_parameterized() {
354+
match (has_output, has_should_panic_attr) {
355+
(true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs),
356+
(true, false) => if generics.is_parameterized() {
357357
No(BadTestSignature::WrongTypeSignature)
358358
} else {
359359
Yes
360360
},
361-
(true, false, _) => No(BadTestSignature::WrongTypeSignature),
362-
(false, _, _) => Yes
361+
(true, _) => No(BadTestSignature::WrongTypeSignature),
362+
(false, _) => Yes
363363
}
364364
}
365365
_ => No(BadTestSignature::NotEvenAFunction),
@@ -398,28 +398,9 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
398398
fn has_bench_signature(cx: &TestCtxt, i: &ast::Item) -> bool {
399399
match i.node {
400400
ast::ItemKind::Fn(ref decl, _, _, _, ref generics, _) => {
401-
let input_cnt = decl.inputs.len();
402-
403-
// If the termination trait is active, the compiler will check that the output
404-
// type implements the `Termination` trait as `libtest` enforces that.
405-
let output_matches = if cx.features.termination_trait_test {
406-
true
407-
} else {
408-
let no_output = match decl.output {
409-
ast::FunctionRetTy::Default(..) => true,
410-
ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => true,
411-
_ => false
412-
};
413-
let tparm_cnt = generics.params.iter()
414-
.filter(|param| param.is_type_param())
415-
.count();
416-
417-
no_output && tparm_cnt == 0
418-
};
419-
420401
// NB: inadequate check, but we're running
421402
// well before resolve, can't get too deep.
422-
input_cnt == 1 && output_matches
403+
decl.inputs.len() == 1
423404
}
424405
_ => false
425406
}
@@ -430,13 +411,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
430411
if has_bench_attr && !has_bench_signature {
431412
let diag = cx.span_diagnostic;
432413

433-
if cx.features.termination_trait_test {
434-
diag.span_err(i.span, "functions used as benches must have signature \
414+
diag.span_err(i.span, "functions used as benches must have signature \
435415
`fn(&mut Bencher) -> impl Termination`");
436-
} else {
437-
diag.span_err(i.span, "functions used as benches must have signature \
438-
`fn(&mut Bencher) -> ()`");
439-
}
440416
}
441417

442418
has_bench_attr && has_bench_signature

src/test/compile-fail/feature-gate-termination_trait_test.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/test/ui/rfc-1937-termination-trait/termination-trait-in-test-should-panic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// compile-flags: --test
1212

13-
#![feature(termination_trait_test)]
1413
#![feature(test)]
1514

1615
extern crate test;

src/test/ui/rfc-1937-termination-trait/termination-trait-in-test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// compile-flags: --test
1212
// run-pass
1313

14-
#![feature(termination_trait_test)]
1514
#![feature(test)]
1615

1716
extern crate test;

src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// compile-flags: --test
1212

13-
#![feature(termination_trait_test)]
14-
1513
use std::num::ParseIntError;
1614

1715
#[test]

0 commit comments

Comments
 (0)