-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-trait-systemArea: Trait systemArea: Trait systemC-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-langRelevant to the language teamRelevant to the language team
Description
trait MyFn<'a> {}
impl<'a, F> MyFn<'a> for F where
F: FnOnce(&'a i32) -> &'a i32 {}
fn foo<F>(f: F) where F: for<'a> MyFn<'a> {}
// This works:
// fn foo<F>(f: F) where F: for<'a> FnOnce(&'a i32) -> &'a i32 {}
fn main() {
foo(|x: &i32| -> &i32 { x });
}
produces:
error: implementation of `MyFn` is not general enough
--> src/main.rs:10:5
|
1 | trait MyFn<'a> {}
| ----------------- trait `MyFn` defined here
...
10 | foo(|x: &i32| -> &i32 { x });
| ^^^ implementation of `MyFn` is not general enough
|
= note: `MyFn<'1>` would have to be implemented for the type `[closure@src/main.rs:10:9: 10:32]`, for any lifetime `'1`...
= note: ...but `MyFn<'_>` is actually implemented for the type `[closure@src/main.rs:10:9: 10:32]`, for some specific lifetime `'2`
But clearly it actually is implemented for any lifetime.
kornelski, u8sand, reynoldsbd, xiaopengli89, ibraheemdev and 74 moreboozook, notverymoe, alnfedorov, mira-ta, PSeitz and 1 more
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-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-trait-systemArea: Trait systemArea: Trait systemC-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-langRelevant to the language teamRelevant to the language team