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

Open
P-E-Meunier opened this issue Jun 5, 2017 · 1 comment

Comments

@P-E-Meunier
Copy link

@P-E-Meunier 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 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants