-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-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.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
This code:
#![feature(closure_lifetime_binder)]
struct Foo<'a, 'b: 'a, 'c: 'a>(*mut &'a (), *mut &'b (), *mut &'c ());
fn bar<'b, 'c>(callback: impl for<'a> Fn(Foo<'a, 'b, 'c>) + 'static) {
let _ = for<'a> |foo: Foo<'a, 'b, 'c>| -> () {
callback(foo);
};
}
error: lifetime may not live long enough
--> src/lib.rs:7:9
|
5 | fn bar<'b, 'c>(callback: impl for<'a> Fn(Foo<'a, 'b, 'c>) + 'static) {
| -- -- lifetime `'c` defined here
| |
| lifetime `'b` defined here
6 | let _ = for<'a> |foo: Foo<'a, 'b, 'c>| -> () {
7 | callback(foo);
| ^^^^^^^^^^^^^ argument requires that `'b` must outlive `'c`
|
= help: consider adding the following bound: `'b: 'c`
error: lifetime may not live long enough
--> src/lib.rs:7:9
|
5 | fn bar<'b, 'c>(callback: impl for<'a> Fn(Foo<'a, 'b, 'c>) + 'static) {
| -- -- lifetime `'c` defined here
| |
| lifetime `'b` defined here
6 | let _ = for<'a> |foo: Foo<'a, 'b, 'c>| -> () {
7 | callback(foo);
| ^^^^^^^^^^^^^ argument requires that `'c` must outlive `'b`
|
= help: consider adding the following bound: `'c: 'b`
help: `'b` and `'c` must be the same: replace one with the other
I think this code should be valid. After all, the type signatures on the closure itself and on the function it's trying to call are identical. I would expect both the closure and the function to implicitly establish bounds 'b: 'a
and 'c: 'a
due to the use of Foo<'a, 'b, 'c>
as an argument. But this shouldn't require 'b: 'c
or 'c: 'b
.
Disclaimer: I don't really understand how implied bounds work.
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-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.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.