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

With impl trait, some variables are not recognised as 'static when used with AsRef. #42451

Closed
P-E-Meunier opened this issue Jun 5, 2017 · 3 comments
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug.

Comments

@P-E-Meunier
Copy link

P-E-Meunier commented Jun 5, 2017

An example is the following code:

fn f() -> impl Future<Item = (), Error = Error> {
    my_future.and_then(move |_| {
        foo("blah")
    })
}
fn foo<T: AsRef<str>>(t: T) {
     unimplemented!()
}

The current nightly rustc complains about unnamed lifetimes in impl trait. It accepts the same code with "blah" replaced by "blah".to_owned().

I believe "blah" should be recognised of lifetime 'static, and this code should be accepted by the compiler.

@eddyb
Copy link
Member

eddyb commented Jun 6, 2017

cc @aturon @nikomatsakis I believe this is hard to accomplish without forcing all lifetimes in the concrete type, that were not inferred to be 'a from impl Trait + 'a, to be 'static. Because they would be inferred if there is an + 'a (AFAIK), so that means impl Trait without lifetimes allows no lifetimes (outside of type parameters of the function) to be anything other than 'static.

On second thought, that sounds close to the new RFC - if it's compatible with it, that's great!

@Mark-Simulacrum Mark-Simulacrum added the A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. label Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 27, 2017
@jyn514
Copy link
Member

jyn514 commented Jul 7, 2021

Triage: I'm not sure how to reproduce the original error, since neither futures::Future nor core::future::Future has Item or Error associated items. I would expect this to probably be fixed though since impl-trait is no longer experimental.

@P-E-Meunier
Copy link
Author

Yes, definitely fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants