mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Fix misleading "borrowed data escapes outside of function" diagnostic
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user