Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leoyvens committed May 10, 2018
1 parent e5f80f2 commit cbdf90a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

pub fn is_ty_anon(&self) -> bool {
match self.sty {
TyAnon(..) => true,
_ => false,
}
}

pub fn is_ty_infer(&self) -> bool {
match self.sty {
TyInfer(_) => true,
Expand Down
10 changes: 9 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,9 +1132,17 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
if id == fn_id {
match entry_type {
config::EntryMain => {
let return_ty_span = decl.output.span();
if ret_ty.is_ty_anon() {
struct_span_err!(fcx.sess(),
return_ty_span,
E0912,
"impl Trait is not allowed in the return type of `main`")
.help("consider using `()`, or a `Result`")
.emit();
}
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(
return_ty_span, fn_id, ObligationCauseCode::MainFunctionType);

Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4770,4 +4770,5 @@ register_diagnostics! {
E0641, // cannot cast to/from a pointer with an unknown kind
E0645, // trait aliases not finished
E0907, // type inside generator must be known in this context
E0912, // impl Trait cannot be returned from main
}

0 comments on commit cbdf90a

Please sign in to comment.