Skip to content

Mistaken "dropped here while still borrowed" with impl trait + match #52706

Closed
@alecmocatta

Description

@alecmocatta

This manifests identically on stable and nightly without and with nll.

struct X;
impl X {
    fn my_method<'a>(&'a self) -> impl Abc + 'a {
        ()
    }
}

trait Abc {}
impl Abc for () {}

fn main() {
    let my_struct = X;
    match my_struct.my_method() {
        _ => (),
    }
    // let _ = my_struct.my_method(); // uncommenting this makes it work
}

(Playground)

Errors:

error[E0597]: `my_struct` does not live long enough
  --> src/main.rs:13:11
   |
13 |     match my_struct.my_method() {
   |           ^^^^^^^^^ borrowed value does not live long enough
...
17 | }
   | - `my_struct` dropped here while still borrowed
   |
   = note: values in a scope are dropped in the opposite order they are created

Metadata

Metadata

Assignees

Labels

A-borrow-checkerArea: The borrow checkerT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions