Skip to content

Confusing 'implicit copy' warnings with outstanding loans #3067

Closed
@bblum

Description

@bblum
fn borrow(_x: &mut ~[()]) { } 

fn consume(+_x: ~[()]) { } 

fn main() {
    let mut x = ~[()];
    let xref = &mut x;
    borrow(xref);
    consume(x);
}

This code compiles, but gives an implicit copy warning on consume(x). Really the reason for this is because of the outstanding loan -- if { let xref ... borrow(xref); } is enclosed in its own block, the warning goes away.

Perhaps the warning should give a bit more info about why the implicit copy is necessary?

(incidentally, if consume's argument is changed from copy-mode to move-mode, it doesn't compile at all, with the "outstanding loan" error.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions