Skip to content

Commit 97b3bf9

Browse files
committed
Stabilize termination_trait
This stabilizes `main` with non-() return types; see rust-lang#48453.
1 parent c5c650d commit 97b3bf9

13 files changed

+22
-40
lines changed

src/librustc_typeck/check/mod.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -1106,25 +1106,22 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11061106
}
11071107
fcx.demand_suptype(span, ret_ty, actual_return_ty);
11081108

1109-
if fcx.tcx.features().termination_trait {
1110-
// If the termination trait language item is activated, check that the main return type
1111-
// implements the termination trait.
1112-
if let Some(term_id) = fcx.tcx.lang_items().termination() {
1113-
if let Some((id, _)) = *fcx.tcx.sess.entry_fn.borrow() {
1114-
if id == fn_id {
1115-
match fcx.sess().entry_type.get() {
1116-
Some(config::EntryMain) => {
1117-
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(ret_ty)));
1118-
let trait_ref = ty::TraitRef::new(term_id, substs);
1119-
let cause = traits::ObligationCause::new(
1120-
span, fn_id, ObligationCauseCode::MainFunctionType);
1121-
1122-
inherited.register_predicate(
1123-
traits::Obligation::new(
1124-
cause, param_env, trait_ref.to_predicate()));
1125-
},
1126-
_ => {},
1127-
}
1109+
// Check that the main return type implements the termination trait.
1110+
if let Some(term_id) = fcx.tcx.lang_items().termination() {
1111+
if let Some((id, _)) = *fcx.tcx.sess.entry_fn.borrow() {
1112+
if id == fn_id {
1113+
match fcx.sess().entry_type.get() {
1114+
Some(config::EntryMain) => {
1115+
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(ret_ty)));
1116+
let trait_ref = ty::TraitRef::new(term_id, substs);
1117+
let cause = traits::ObligationCause::new(
1118+
span, fn_id, ObligationCauseCode::MainFunctionType);
1119+
1120+
inherited.register_predicate(
1121+
traits::Obligation::new(
1122+
cause, param_env, trait_ref.to_predicate()));
1123+
},
1124+
_ => {},
11281125
}
11291126
}
11301127
}

src/librustc_typeck/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
208208
}
209209

210210
let actual = tcx.fn_sig(main_def_id);
211-
let expected_return_type = if tcx.lang_items().termination().is_some()
212-
&& tcx.features().termination_trait {
211+
let expected_return_type = if tcx.lang_items().termination().is_some() {
213212
// we take the return type of the given main function, the real check is done
214213
// in `check_fn`
215214
actual.output().skip_binder()

src/libstd/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@
308308
#![feature(str_char)]
309309
#![feature(str_internals)]
310310
#![feature(str_utf16)]
311-
#![feature(termination_trait)]
312311
#![feature(test, rustc_private)]
313312
#![feature(thread_local)]
314313
#![feature(toowned_clone_into)]
@@ -325,6 +324,7 @@
325324
#![cfg_attr(test, feature(update_panic_count))]
326325
#![cfg_attr(windows, feature(used))]
327326
#![cfg_attr(stage0, feature(never_type))]
327+
#![cfg_attr(stage0, feature(termination_trait))]
328328

329329
#![default_lib_allocator]
330330

src/libsyntax/feature_gate.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,6 @@ declare_features! (
429429
// `foo.rs` as an alternative to `foo/mod.rs`
430430
(active, non_modrs_mods, "1.24.0", Some(44660), None),
431431

432-
// Termination trait in main (RFC 1937)
433-
(active, termination_trait, "1.24.0", Some(43301), None),
434-
435432
// Termination trait in tests (RFC 1937)
436433
(active, termination_trait_test, "1.24.0", Some(48854), None),
437434

@@ -558,6 +555,8 @@ declare_features! (
558555
(accepted, inclusive_range_syntax, "1.26.0", Some(28237), None),
559556
// allow `..=` in patterns (RFC 1192)
560557
(accepted, dotdoteq_in_patterns, "1.26.0", Some(28237), None),
558+
// Termination trait in main (RFC 1937)
559+
(accepted, termination_trait, "1.26.0", Some(43301), None),
561560
);
562561

563562
// If you change this, please modify src/doc/unstable-book as well. You must

src/test/compile-fail/feature-gate-termination_trait.rs renamed to src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-i32.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
fn main() -> i32 { //~ ERROR main function has wrong type [E0580]
11+
fn main() -> i32 {
12+
//~^ ERROR the trait bound `i32: std::process::Termination` is not satisfied [E0277]
1213
0
1314
}

src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-wrong-type.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
#![feature(termination_trait)]
1110

1211
fn main() -> char {
1312
//~^ ERROR: the trait bound `char: std::process::Termination` is not satisfied

src/test/compile-fail/rfc-1937-termination-trait/termination-trait-not-satisfied.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(termination_trait)]
12-
1311
struct ReturnType {}
1412

1513
fn main() -> ReturnType { //~ ERROR `ReturnType: std::process::Termination` is not satisfied

src/test/run-fail/rfc-1937-termination-trait/termination-trait-for-never.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(termination_trait)]
12-
1311
// error-pattern:oh, dear
1412

1513
fn main() -> ! {

src/test/run-fail/rfc-1937-termination-trait/termination-trait-for-result-box-error_err.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// must-compile-successfully
1212
// failure-status: 1
1313

14-
#![feature(termination_trait)]
15-
1614
use std::io::{Error, ErrorKind};
1715

1816
fn main() -> Result<(), Box<Error>> {

src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-empty.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(termination_trait)]
12-
1311
fn main() {}

src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-exitcode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(termination_trait)]
1211
#![feature(process_exitcode_placeholder)]
1312

1413
use std::process::ExitCode;

src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-result-box-error_ok.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(termination_trait)]
12-
1311
use std::io::Error;
1412

1513
fn main() -> Result<(), Box<Error>> {

src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-result.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(termination_trait)]
12-
1311
use std::io::Error;
1412

1513
fn main() -> Result<(), Error> {

0 commit comments

Comments
 (0)