Skip to content

Misleading unused_mut warning when moving into a proc #16671

Closed
@tomjakubowski

Description

@tomjakubowski

This example:

fn main() {
    let mut stdin = std::io::stdio::stdin();
    spawn(proc() {
        for line in stdin.lines() {
            print!("{}", line);
        }
    });
}

Gives this warning:

<anon>:2:9: 2:18 warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
<anon>:2     let mut stdin = std::io::stdio::stdin();
                 ^~~~~~~~~

However, removing the mut is an error:

<anon>:4:21: 4:26 error: cannot borrow immutable captured outer variable in a proc `stdin` as mutable
<anon>:4         for line in stdin.lines() {
                             ^~~~~
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions