about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-12-22 19:01:28 +0100
committerGitHub <noreply@github.com>2023-12-22 19:01:28 +0100
commitb24e8784de59cc159334de21b4efa0e7f7001324 (patch)
tree5b61c9868454540ff344f2e4c06c53371039c183
parent41fbd25b73305939f43c1d0705e5ed1de1feb6da (diff)
parentd3f466a3a77d6d32e8e31ab9ccb61435938928a8 (diff)
downloadrust-b24e8784de59cc159334de21b4efa0e7f7001324.tar.gz
rust-b24e8784de59cc159334de21b4efa0e7f7001324.zip
Rollup merge of #119215 - mu001999:fix/119209, r=Nilstrieb
Emits error if has bound regions

Fixes #119209
-rw-r--r--compiler/rustc_hir_analysis/src/check/entry.rs5
-rw-r--r--tests/ui/entry-point/return-ty-has-bound-vars.rs3
-rw-r--r--tests/ui/entry-point/return-ty-has-bound-vars.stderr9
3 files changed, 16 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/entry.rs b/compiler/rustc_hir_analysis/src/check/entry.rs
index 1d737e17e82..a82853a1303 100644
--- a/compiler/rustc_hir_analysis/src/check/entry.rs
+++ b/compiler/rustc_hir_analysis/src/check/entry.rs
@@ -124,7 +124,10 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
     if let Some(term_did) = tcx.lang_items().termination() {
         let return_ty = main_fnsig.output();
         let return_ty_span = main_fn_return_type_span(tcx, main_def_id).unwrap_or(main_span);
-        let return_ty = return_ty.skip_binder();
+        let Some(return_ty) = return_ty.no_bound_vars() else {
+            tcx.sess.emit_err(errors::MainFunctionReturnTypeGeneric { span: return_ty_span });
+            return;
+        };
         let infcx = tcx.infer_ctxt().build();
         let cause = traits::ObligationCause::new(
             return_ty_span,
diff --git a/tests/ui/entry-point/return-ty-has-bound-vars.rs b/tests/ui/entry-point/return-ty-has-bound-vars.rs
new file mode 100644
index 00000000000..0995ce06160
--- /dev/null
+++ b/tests/ui/entry-point/return-ty-has-bound-vars.rs
@@ -0,0 +1,3 @@
+// issue-119209
+
+fn main<'a>(_: &'a i32) -> &'a () { &() } //~ERROR `main` function return type is not allowed to have generic parameters
diff --git a/tests/ui/entry-point/return-ty-has-bound-vars.stderr b/tests/ui/entry-point/return-ty-has-bound-vars.stderr
new file mode 100644
index 00000000000..e7aab839f31
--- /dev/null
+++ b/tests/ui/entry-point/return-ty-has-bound-vars.stderr
@@ -0,0 +1,9 @@
+error[E0131]: `main` function return type is not allowed to have generic parameters
+  --> $DIR/return-ty-has-bound-vars.rs:3:28
+   |
+LL | fn main<'a>(_: &'a i32) -> &'a () { &() }
+   |                            ^^^^^^
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0131`.