Skip to content

Borrow checker works wrongly with returned values. #37407

@loyd

Description

@loyd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions