Skip to content

Commit cbdf90a

Browse files
committed
wip
1 parent e5f80f2 commit cbdf90a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/librustc/ty/sty.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
12991299
}
13001300
}
13011301

1302+
pub fn is_ty_anon(&self) -> bool {
1303+
match self.sty {
1304+
TyAnon(..) => true,
1305+
_ => false,
1306+
}
1307+
}
1308+
13021309
pub fn is_ty_infer(&self) -> bool {
13031310
match self.sty {
13041311
TyInfer(_) => true,

src/librustc_typeck/check/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1132,9 +1132,17 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11321132
if id == fn_id {
11331133
match entry_type {
11341134
config::EntryMain => {
1135+
let return_ty_span = decl.output.span();
1136+
if ret_ty.is_ty_anon() {
1137+
struct_span_err!(fcx.sess(),
1138+
return_ty_span,
1139+
E0912,
1140+
"impl Trait is not allowed in the return type of `main`")
1141+
.help("consider using `()`, or a `Result`")
1142+
.emit();
1143+
}
11351144
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(ret_ty)));
11361145
let trait_ref = ty::TraitRef::new(term_id, substs);
1137-
let return_ty_span = decl.output.span();
11381146
let cause = traits::ObligationCause::new(
11391147
return_ty_span, fn_id, ObligationCauseCode::MainFunctionType);
11401148

src/librustc_typeck/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4770,4 +4770,5 @@ register_diagnostics! {
47704770
E0641, // cannot cast to/from a pointer with an unknown kind
47714771
E0645, // trait aliases not finished
47724772
E0907, // type inside generator must be known in this context
4773+
E0912, // impl Trait cannot be returned from main
47734774
}

0 commit comments

Comments
 (0)