-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Return impl for<'a> Fn(&'a) incorrectly rejected for closures #105528
Copy link
Copy link
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-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)C-bugCategory: This is a bug.Category: This is a bug.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.
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-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)C-bugCategory: This is a bug.Category: This is a bug.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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I ran into a compile error while writing some iterator adapters involving building (types containing) closures in a function returning (types containing)
impl for<'a> Fn(&'a), which I narrowed down to the following example:This function fails to typecheck, seemingly because the return type is inferred to only implement
Fn(&())rather thanfor <'a> Fn(&'a ()).Note that replacing the body with an unconditional
|_| ()instead works as expected, and using functions rather than closures also compiles without errors, see playground for more examples.I'm on Rust 1.65.0 but the playground shows the same happening in beta and nightly too.
Seems related to #99991 and maybe #98437 (that I could find), but they are about trait bounds in input types rather than return
impl, and here it actually does work as long as the closure is returned unconditionally, though feel free to close as duplicate if it's ultimately the same root issue.`cargo check` output