Skip to content

Commit 136dd5a

Browse files
authored
Unrolled build for #155295
Rollup merge of #155295 - lapla-cogito:issue_154350, r=JohnTitor Fix misleading "borrowed data escapes outside of function" diagnostic Fixes #154350 Fall back to `report_general_error()` when `fr_name_and_span` is `None` in function items, since the "escaping data" framing is only appropriate for closures capturing outside variables.
2 parents 2f201bc + b17a3e2 commit 136dd5a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
686686
|| (*category == ConstraintCategory::Assignment
687687
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
688688
|| self.regioncx.universal_regions().defining_ty.is_const()
689+
|| (fr_name_and_span.is_none()
690+
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
689691
{
690692
return self.report_general_error(errci);
691693
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/154350
2+
3+
fn func<'a>(f: impl FnOnce(fn(&'a i32)), x: fn(&'static i32)) {
4+
f(x);
5+
//~^ ERROR lifetime may not live long enough
6+
}
7+
8+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/fn-ptr-lifetime-mismatch-with-impl-trait-arg.rs:4:5
3+
|
4+
LL | fn func<'a>(f: impl FnOnce(fn(&'a i32)), x: fn(&'static i32)) {
5+
| -- lifetime `'a` defined here
6+
LL | f(x);
7+
| ^^^^ argument requires that `'a` must outlive `'static`
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)