Skip to content

Commit

Permalink
typeck: Report main return type errors on return type span
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Mar 20, 2018
1 parent 5ccf3ff commit 72334fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
' '
}
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 72334fe

Please sign in to comment.