Skip to content

NLL erroneous Warning: variable does not need to be mutable #50461

Closed
@rukai

Description

@rukai
#![feature(nll)]
struct Foo {
    pub value: i32
}

// triggers bug
fn use_foo_mut(mut foo: Foo) {
    foo = foo;
    println!("{}", foo.value);
}

// does not trigger bug
fn use_i32_mut(mut i: i32) {
    i = i;
    println!("{}", i);
}

fn main() {
    use_foo_mut(Foo { value: 413 });
    use_i32_mut(413);
}

gives:

warning: variable does not need to be mutable
 --> src/main.rs:8:16
  |
8 | fn use_foo_mut(mut foo: Foo) {
  |                ----^^^
  |                |
  |                help: remove this `mut`
  |
  = note: #[warn(unused_mut)] on by default

If I remove the mut then I get a compile error.

Compiled with nightly-2018-05-05

This is not related to #50343 as that has been fixed in the nightly I am using.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)NLL-diagnosticsWorking towards the "diagnostic parity" goal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions