You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structContext;structFoo<'a>(&'a Context);structBar<'a>(&'a Foo<'a>);structBaz<'a>(&'a Context);impl<'a>DropforBaz<'a>{fndrop(&mutself){}}impl<'a>Bar<'a>{fnnext(&mutself) -> Option<Baz<'a>>{None}}fnutil(ctx:&Context){let foo = Foo(ctx);letmut bar = Bar(&foo);match bar.next(){ _ => ()}// this fails// return match bar.next() { _ => () }; // this works}
error: `foo` does not live long enough
--> <anon>:24:1
|
20 | let mut bar = Bar(&foo);
| --- borrow occurs here
...
24 | }
| ^ `foo` dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are created
error: aborting due to previous error
Probably a duplicate of #17462(scratch that, not related), #22449, and #21114. May also be related to #22321. I thought there was a more "canonical" issue for this but I can't find it.
Playground
Note how the message even states that
bar
is dropped first (reverse order) while complaining that it outlivesfoo
.This works fine if you remove
Baz
'sDrop
impl or - interestingly - if you just use thereturn
keyword instead of "naturally" returning the value.The text was updated successfully, but these errors were encountered: