Fix misleading "borrowed data escapes outside of function" diagnostic

This commit is contained in:
lapla
2026-04-15 00:33:36 +09:00
parent 12f35ad39e
commit b17a3e2f2d
3 changed files with 20 additions and 0 deletions
@@ -686,6 +686,8 @@ fn report_escaping_data_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<
|| (*category == ConstraintCategory::Assignment
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
|| self.regioncx.universal_regions().defining_ty.is_const()
|| (fr_name_and_span.is_none()
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
{
return self.report_general_error(errci);
}
@@ -0,0 +1,8 @@
// Regression test for https://github.com/rust-lang/rust/issues/154350
fn func<'a>(f: impl FnOnce(fn(&'a i32)), x: fn(&'static i32)) {
f(x);
//~^ ERROR lifetime may not live long enough
}
fn main() {}
@@ -0,0 +1,10 @@
error: lifetime may not live long enough
--> $DIR/fn-ptr-lifetime-mismatch-with-impl-trait-arg.rs:4:5
|
LL | fn func<'a>(f: impl FnOnce(fn(&'a i32)), x: fn(&'static i32)) {
| -- lifetime `'a` defined here
LL | f(x);
| ^^^^ argument requires that `'a` must outlive `'static`
error: aborting due to 1 previous error