-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
The owning_ref crate has a couple test failures starting with Rust 1.23, which worked fine on 1.22. It is fixed by Kimundi/owning-ref-rs#43, but I wanted to see if this is a deliberate compiler change. The only compatibility note for 1.23 that sounds like it might be related is regarding #45852, but I'm not sure.
Reduced example, playground:
fn map<F, T, U>(x: &T, f: F) -> &U
where
F: FnOnce(&T) -> &U,
{
f(x)
}
fn borrow<'a>(a: &'a &[i32; 2]) -> &'a i32 {
&a[0]
}
fn main() {
let foo = [413, 612];
let bar = &foo;
map(&bar, borrow); // OK
map(&bar, |a: &&[i32; 2]| &a[0]); // does not live long enough
}
This example works on 1.22, but fails on 1.23 through nightly:
error[E0597]: `a[..]` does not live long enough
--> src/main.rs:18:32
|
18 | map(&bar, |a: &&[i32; 2]| &a[0]); // does not live long enough
| ^^^^- borrowed value only lives until here
| |
| does not live long enough
|
note: borrowed value must be valid for the anonymous lifetime #2 defined on the body at 18:15...
--> src/main.rs:18:15
|
18 | map(&bar, |a: &&[i32; 2]| &a[0]); // does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.