Skip to content

Commit 4830325

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

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

compiler/rustc_hir_analysis/src/check/entry.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +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-
let return_ty = return_ty.skip_binder();
127+
let Some(return_ty) = return_ty.no_bound_vars() else {
128+
tcx.sess.emit_err(errors::MainFunctionReturnTypeGeneric { span: return_ty_span });
129+
return;
130+
};
128131
let infcx = tcx.infer_ctxt().build();
129132
let cause = traits::ObligationCause::new(
130133
return_ty_span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// issue-119209
2+
3+
type Foo<'a> = impl PartialEq; //~ERROR `impl Trait` in type aliases is unstable
4+
5+
fn main<'a>(_: &'a i32) -> Foo<'a> {} //~ERROR `main` function return type is not allowed to have generic parameters
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0658]: `impl Trait` in type aliases is unstable
2+
--> $DIR/return-ty-has-bound-vars.rs:3:16
3+
|
4+
LL | type Foo<'a> = impl PartialEq;
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
8+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
9+
10+
error[E0131]: `main` function return type is not allowed to have generic parameters
11+
--> $DIR/return-ty-has-bound-vars.rs:5:28
12+
|
13+
LL | fn main<'a>(_: &'a i32) -> Foo<'a> {}
14+
| ^^^^^^^
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0131, E0658.
19+
For more information about an error, try `rustc --explain E0131`.

0 commit comments

Comments
 (0)