about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-02-12 06:07:40 +0100
committerGitHub <noreply@github.com>2025-02-12 06:07:40 +0100
commit77a1d6b266fa6254d65fc7cc2a4401bf6426290f (patch)
tree93ae28a6080b626c1bb313ff492d200d83bc05c0
parent86ebf42801c1fe61f4fcece96dc228eff605b8ea (diff)
parent6ffe6dd826d737daf363c1251621b7da362a437d (diff)
downloadrust-77a1d6b266fa6254d65fc7cc2a4401bf6426290f.tar.gz
rust-77a1d6b266fa6254d65fc7cc2a4401bf6426290f.zip
Rollup merge of #136891 - compiler-errors:unconstrained-anon-lt, r=lqd
Check sig for errors before checking for unconstrained anonymous lifetime

Fixes #136841
-rw-r--r--compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs44
-rw-r--r--tests/ui/async-await/unconstrained-lifetimes.rs9
-rw-r--r--tests/ui/async-await/unconstrained-lifetimes.stderr9
3 files changed, 41 insertions, 21 deletions
diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
index e58cb2ff592..697852c5ed3 100644
--- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
+++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
@@ -2561,27 +2561,29 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
         // reject function types that violate cmse ABI requirements
         cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi, bare_fn_ty);
 
-        // Find any late-bound regions declared in return type that do
-        // not appear in the arguments. These are not well-formed.
-        //
-        // Example:
-        //     for<'a> fn() -> &'a str <-- 'a is bad
-        //     for<'a> fn(&'a String) -> &'a str <-- 'a is ok
-        let inputs = bare_fn_ty.inputs();
-        let late_bound_in_args =
-            tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i| i.to_owned()));
-        let output = bare_fn_ty.output();
-        let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(output);
-
-        self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
-            struct_span_code_err!(
-                self.dcx(),
-                decl.output.span(),
-                E0581,
-                "return type references {}, which is not constrained by the fn input types",
-                br_name
-            )
-        });
+        if !bare_fn_ty.references_error() {
+            // Find any late-bound regions declared in return type that do
+            // not appear in the arguments. These are not well-formed.
+            //
+            // Example:
+            //     for<'a> fn() -> &'a str <-- 'a is bad
+            //     for<'a> fn(&'a String) -> &'a str <-- 'a is ok
+            let inputs = bare_fn_ty.inputs();
+            let late_bound_in_args =
+                tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i| i.to_owned()));
+            let output = bare_fn_ty.output();
+            let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(output);
+
+            self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
+                struct_span_code_err!(
+                    self.dcx(),
+                    decl.output.span(),
+                    E0581,
+                    "return type references {}, which is not constrained by the fn input types",
+                    br_name
+                )
+            });
+        }
 
         bare_fn_ty
     }
diff --git a/tests/ui/async-await/unconstrained-lifetimes.rs b/tests/ui/async-await/unconstrained-lifetimes.rs
new file mode 100644
index 00000000000..50ab7bae73d
--- /dev/null
+++ b/tests/ui/async-await/unconstrained-lifetimes.rs
@@ -0,0 +1,9 @@
+//@ edition: 2021
+
+// Make sure we don't complain about the implicit `-> impl Future` capturing an
+// unconstrained anonymous lifetime.
+
+async fn foo(_: Missing<'_>) {}
+//~^ ERROR cannot find type `Missing` in this scope
+
+fn main() {}
diff --git a/tests/ui/async-await/unconstrained-lifetimes.stderr b/tests/ui/async-await/unconstrained-lifetimes.stderr
new file mode 100644
index 00000000000..18a46a3b555
--- /dev/null
+++ b/tests/ui/async-await/unconstrained-lifetimes.stderr
@@ -0,0 +1,9 @@
+error[E0412]: cannot find type `Missing` in this scope
+  --> $DIR/unconstrained-lifetimes.rs:6:17
+   |
+LL | async fn foo(_: Missing<'_>) {}
+   |                 ^^^^^^^ not found in this scope
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0412`.