Skip to content

Commit c0feb56

Browse files
committed
Emits error if has bound regions
1 parent a7d6f42 commit c0feb56

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

compiler/rustc_hir_analysis/src/check/entry.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir as hir;
22
use rustc_hir::Node;
33
use rustc_infer::infer::TyCtxtInferExt;
4-
use rustc_middle::ty::{self, Ty, TyCtxt};
4+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
55
use rustc_session::config::EntryFnType;
66
use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
77
use rustc_span::{symbol::sym, Span};
@@ -124,6 +124,10 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
124124
if let Some(term_did) = tcx.lang_items().termination() {
125125
let return_ty = main_fnsig.output();
126126
let return_ty_span = main_fn_return_type_span(tcx, main_def_id).unwrap_or(main_span);
127+
if return_ty.has_bound_regions() {
128+
tcx.sess.emit_err(errors::MainFunctionReturnTypeGeneric { span: return_ty_span });
129+
return;
130+
}
127131
let return_ty = return_ty.skip_binder();
128132
let infcx = tcx.infer_ctxt().build();
129133
let cause = traits::ObligationCause::new(

tests/ui/entry-point/issue-119209.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type Foo<'a, 'b> = (i32, impl PartialEq); //~ ERROR `impl Trait` in type aliases is unstable
2+
fn main<'a, 'main>(i: &'a i32) -> Foo<'a, 'b> {} //~ ERROR use of undeclared lifetime name `'b`
3+
//~^ ERROR mismatched types
4+
//~^^ ERROR `main` function return type is not allowed to have generic parameters
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error[E0261]: use of undeclared lifetime name `'b`
2+
--> $DIR/issue-119209.rs:2:43
3+
|
4+
LL | fn main<'a, 'main>(i: &'a i32) -> Foo<'a, 'b> {}
5+
| - ^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'b` here: `'b,`
8+
9+
error[E0658]: `impl Trait` in type aliases is unstable
10+
--> $DIR/issue-119209.rs:1:26
11+
|
12+
LL | type Foo<'a, 'b> = (i32, impl PartialEq);
13+
| ^^^^^^^^^^^^^^
14+
|
15+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
16+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
17+
18+
error[E0308]: mismatched types
19+
--> $DIR/issue-119209.rs:2:35
20+
|
21+
LL | fn main<'a, 'main>(i: &'a i32) -> Foo<'a, 'b> {}
22+
| ---- ^^^^^^^^^^^ expected `(i32, _)`, found `()`
23+
| |
24+
| implicitly returns `()` as its body has no tail or `return` expression
25+
|
26+
= note: expected tuple `(i32, _)`
27+
found unit type `()`
28+
29+
error[E0131]: `main` function return type is not allowed to have generic parameters
30+
--> $DIR/issue-119209.rs:2:35
31+
|
32+
LL | fn main<'a, 'main>(i: &'a i32) -> Foo<'a, 'b> {}
33+
| ^^^^^^^^^^^
34+
35+
error: aborting due to 4 previous errors
36+
37+
Some errors have detailed explanations: E0131, E0261, E0308, E0658.
38+
For more information about an error, try `rustc --explain E0131`.

0 commit comments

Comments
 (0)