typeck: Report main return type errors on return type span

This commit is contained in:
Tyler Mandry 2018-03-20 14:19:16 -05:00
parent 5ccf3ffab2
commit 72334fee6f
3 changed files with 14 additions and 3 deletions

View file

@ -1114,8 +1114,9 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
Some(config::EntryMain) => {
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(ret_ty)));
let trait_ref = ty::TraitRef::new(term_id, substs);
let return_ty_span = decl.output.span();
let cause = traits::ObligationCause::new(
span, fn_id, ObligationCauseCode::MainFunctionType);
return_ty_span, fn_id, ObligationCauseCode::MainFunctionType);
inherited.register_predicate(
traits::Obligation::new(

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:`main` can only return types that implement std::process::Termination, not `char
fn main() -> char {
fn main() -> char { //~ ERROR
' '
}

View file

@ -0,0 +1,11 @@
error[E0277]: the trait bound `char: std::process::Termination` is not satisfied
--> $DIR/termination-trait-main-wrong-type.rs:11:14
|
LL | fn main() -> char { //~ ERROR
| ^^^^ `main` can only return types that implement std::process::Termination, not `char`
|
= help: the trait `std::process::Termination` is not implemented for `char`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.