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

Bunogi opened this issue Sep 13, 2019 · 4 comments


Copy link

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.

struct A<'a> {
    inner: Vec<&'a str>,

struct B {}

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

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)|_| ())?)

fn main() {

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/
18 |     Ok(b.something_with_a(a)|_| ())?)
   |        ^--------------------
   |        |
   |        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.


$ rustc +nightly-2019-09-11 --version
rustc 1.39.0-nightly (34e82a7b7 2019-09-10)

This comment has been minimized.

Copy link

commented Sep 17, 2019

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.


This comment has been minimized.

Copy link

commented Sep 18, 2019

I hit the same issue with something like this:

async fn something<B: Borrow<Foo>>(b: B) {

This comment has been minimized.

Copy link

commented Sep 19, 2019

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


This comment has been minimized.

Copy link

commented Sep 19, 2019

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

@bstrie bstrie referenced this issue Sep 23, 2019
10 of 11 tasks complete
@cramertj cramertj closed this Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
7 participants
You can’t perform that action at this time.