Skip to content

Diagnostic when using moved value in loop{} could be clearer #31874

Closed
@vi

Description

@vi

Consider this error message:

struct Qqq;
fn consume(_:Qqq){}
fn main() {
    let a = Qqq;
    consume(a);
    consume(a);
}
<anon>:6:13: 6:14 error: use of moved value: `a` [E0382]
<anon>:6     consume(a);
                     ^
<anon>:5:13: 5:14 note: `a` moved here because it has type `Qqq`, which is non-copyable
<anon>:5     consume(a);

It look more or less clear. But if we move and try to use on the same line:

struct Qqq;
fn consume(_:Qqq){}
fn main() {
    let a = Qqq;
    loop {
        consume(a);
    }
}

the diagnostic looks less clear:

<anon>:6:17: 6:18 error: use of moved value: `a` [E0382]
<anon>:6         consume(a);
                         ^
<anon>:6:17: 6:18 help: see the detailed explanation for E0382
note: `a` was previously moved here (where?) because it has type `Qqq`, which is non-copyable

Note the absence of filename and line number.

Maybe it should point to the same line <anon>:6 or there should dedicated message mentioning the loop...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions