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

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

Closed
alecmocatta opened this issue Jul 25, 2018 · 5 comments
Closed
Assignees
Labels
A-borrow-checker Area: The borrow checker T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alecmocatta
Copy link
Contributor

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
@memoryruins memoryruins added the A-borrow-checker Area: The borrow checker label Aug 31, 2018
@nikomatsakis nikomatsakis added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-NLL Area: Non Lexical Lifetimes (NLL) labels Aug 31, 2018
@nikomatsakis
Copy link
Contributor

Curious, needs some more investigation.

@pnkfelix
Copy link
Member

pnkfelix commented Sep 4, 2018

assigning to self for preliminary investigation.

@pnkfelix pnkfelix self-assigned this Sep 4, 2018
@pnkfelix
Copy link
Member

pnkfelix commented Sep 7, 2018

(removing NLL label since the bug is stated as occurring with and without NLL.)

@pnkfelix pnkfelix removed the A-NLL Area: Non Lexical Lifetimes (NLL) label Sep 7, 2018
@eddyb
Copy link
Member

eddyb commented Sep 13, 2018

You don't need that specific statement, even just adding a semicolon fixes it.

@pnkfelix
Copy link
Member

pnkfelix commented Sep 13, 2018

Discussed at meeting. This is similar to a number of other cases I was looking at today (namely #53528 and #53450), in that impl Trait's are assumed to potentially have a destructor, which in turn have implications for how they are treated during borrow-checking.

In our current implementation of the rvalue-lifetime and drop-check rules in particular #21114 and #46413, you can end up in scenarios where the last expression in a block needs to have a semi-colon added to it, or you get borrow-check errors.

It would be good for us to address those cases, potentially as part of longer term NLL work, but its not something we're treating as a high priority item in the short term.

Therefore, I'm closing this bug as a duplicate of #21114

alecmocatta added a commit to alecmocatta/serde_pipe that referenced this issue Oct 17, 2018
alecmocatta added a commit to alecmocatta/serde_pipe that referenced this issue Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker 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

5 participants