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

Lifetime errors on nightly-2019-09-11 but not nightly-2019-09-10 #64433

Closed
Bunogi opened this issue Sep 13, 2019 · 4 comments
Closed

Lifetime errors on nightly-2019-09-11 but not nightly-2019-09-10 #64433

Bunogi opened this issue Sep 13, 2019 · 4 comments
Labels
A-async-await Area: Async & Await A-lifetimes Area: lifetime related AsyncAwait-Polish Async-await issues that are part of the "polish" area T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Bunogi
Copy link

Bunogi commented Sep 13, 2019

The code below will compile without warnings on nightly-2019-09-10, but returns a lifetime error on nightly-2019-09-11 and later.

#[derive(Debug)]
struct A<'a> {
    inner: Vec<&'a str>,
}

struct B {}

impl B {
    async fn something_with_a(&mut self, a: A<'_>) -> Result<(), String> {
        println!("{:?}", a);
        Ok(())
    }
}

async fn can_error(some_string: &str) -> Result<(), String> {
    let a = A { inner: vec![some_string, "foo"] };
    let mut b = B {};
    Ok(b.something_with_a(a).await.map(|_| ())?)
}

fn main() {
    futures::executor::block_on(can_error("foo")).unwrap();
}

cargo +nightly-2019-09-10 build compiles the code without warnings, and cargo +nightly-2019-09-11 build gives the following error:

error[E0597]: `b` does not live long enough
  --> src/main.rs:18:8
   |
18 |     Ok(b.something_with_a(a).await.map(|_| ())?)
   |        ^--------------------
   |        |
   |        borrowed value does not live long enough
   |        a temporary with access to the borrow is created here ...
19 | }
   | -
   | |
   | `b` dropped here while still borrowed
   | ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `impl core::future::future::Future`
   |
   = note: The temporary is part of an expression at the end of a block. Consider forcing this temporary to be dropped sooner, before the block's local variables are dropped. For example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block.

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.
error: Could not compile `bugreport`.

To learn more, run the command again with --verbose.

Meta

$ rustc +nightly-2019-09-11 --version
rustc 1.39.0-nightly (34e82a7b7 2019-09-10)
@estebank estebank added A-lifetimes Area: lifetime related regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. AsyncAwait-Unclear T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 13, 2019
@matthewjasper matthewjasper removed the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Sep 13, 2019
@jonas-schievink jonas-schievink added the A-async-await Area: Async & Await label Sep 15, 2019
@nikomatsakis nikomatsakis added the AsyncAwait-Polish Async-await issues that are part of the "polish" area label Sep 17, 2019
@nikomatsakis
Copy link
Contributor

This too is fallout from #64292, similar to #64477. I've written up a long report on the change that caused this and its motivations. The report also discussed whether we should consider revering that change, and what that would mean.

Let's keep discussion about the pro/con of the decision confined to #64477 though.

@PvdBerg1998
Copy link

I hit the same issue with something like this:

async fn something<B: Borrow<Foo>>(b: B) {
   other(b.borrow()).await;
}

@nikomatsakis
Copy link
Contributor

The original example, at least, is fixed by #64584

@nikomatsakis
Copy link
Contributor

Also this is likely a duplicate of #64391 at this point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-lifetimes Area: lifetime related AsyncAwait-Polish Async-await issues that are part of the "polish" area 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

7 participants