Skip to content

Borrow checker works wrongly with returned values. #37407

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
loyd opened this issue Oct 25, 2016 · 3 comments
Closed

Borrow checker works wrongly with returned values. #37407

loyd opened this issue Oct 25, 2016 · 3 comments
Labels
A-borrow-checker Area: The borrow checker

Comments

@loyd
Copy link

loyd commented Oct 25, 2016

Unfortunately I haven't found an open bug on this subject.

I tried this code:

struct A(Vec<u32>);

impl A {
    fn drain(self) -> Vec<u32> {
        let mut nums = self.0;
        nums.drain(..).collect()          // error: `nums` does not live long enough

        // but it works fine:
        // return nums.drain(..).collect();
    }
}

Try it

@jonas-schievink
Copy link
Contributor

I think this is #21114

@TimNN
Copy link
Contributor

TimNN commented Oct 25, 2016

Essentially the same issue as #31723, I think.

Edit: (why weren't you auto updating the comments, github?) @jonas-schievink's issue is probably the "better" duplicate.

@apasel422 apasel422 added the A-borrow-checker Area: The borrow checker label Dec 28, 2016
@Mark-Simulacrum
Copy link
Member

Closing in favor of #21114. Please reopen if that's incorrect, but from what I can tell this is a duplicate of that issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-borrow-checker Area: The borrow checker
Projects
None yet
Development

No branches or pull requests

5 participants