Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong lifetime is inferred in the argument of closure when given more specific type. #51616

Open
oxalica opened this issue Jun 18, 2018 · 0 comments
Labels
A-closures Area: closures (`|args| { .. }`) A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. A-lifetimes Area: lifetime related C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oxalica
Copy link
Contributor

oxalica commented Jun 18, 2018

I have lifetime bounds to a closure through a trait like this.

trait Closure<'t> {}
impl<'t, F: Fn(&'t ())> Closure<'t> for F {}

fn restrict_trait(_: impl Closure<'static>) {}

When I call restrict_trait(|r| ...), I'll get r: &'static () inside the closure. But when using restrict_trait(|r: &_| ...), the lifetime of r inferred is not 'static anymore.

Here is the detailed example

@estebank estebank added A-lifetimes Area: lifetime related A-closures Area: closures (`|args| { .. }`) A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. labels Jan 19, 2019
@JohnTitor JohnTitor added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: closures (`|args| { .. }`) A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. A-lifetimes Area: lifetime related C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants