Skip to content

Commit b24e878

Browse files
authored
Rollup merge of rust-lang#119215 - mu001999:fix/119209, r=Nilstrieb
Emits error if has bound regions Fixes rust-lang#119209
2 parents 41fbd25 + d3f466a commit b24e878

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Diff for: 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,

Diff for: tests/ui/entry-point/return-ty-has-bound-vars.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// issue-119209
2+
3+
fn main<'a>(_: &'a i32) -> &'a () { &() } //~ERROR `main` function return type is not allowed to have generic parameters

Diff for: tests/ui/entry-point/return-ty-has-bound-vars.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0131]: `main` function return type is not allowed to have generic parameters
2+
--> $DIR/return-ty-has-bound-vars.rs:3:28
3+
|
4+
LL | fn main<'a>(_: &'a i32) -> &'a () { &() }
5+
| ^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0131`.

0 commit comments

Comments
 (0)