rust/tests/ui/regions/account-for-lifetimes-in-closure-suggestion.rs
Esteban Küber a2298a6f19 Do not ICE when suggesting dereferencing closure arg
Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid.

Fix #125634, fix #124563.
2024-06-24 03:39:54 +00:00

20 lines
391 B
Rust

// #125634
struct Thing;
// Invariant in 'a, Covariant in 'b
struct TwoThings<'a, 'b>(*mut &'a (), &'b mut ());
impl Thing {
fn enter_scope<'a>(self, _scope: impl for<'b> FnOnce(TwoThings<'a, 'b>)) {}
}
fn foo() {
Thing.enter_scope(|ctx| {
SameLifetime(ctx); //~ ERROR lifetime may not live long enough
});
}
struct SameLifetime<'a>(TwoThings<'a, 'a>);
fn main() {}