Skip to content

Value assigned is never read #49171

Open
Open
@kkayal

Description

@kkayal

I have the following simple code:

fn main() {
	let mut foo = String::new();
	foo = "Hi!".to_string();

	println!("{}", foo);
}

The compiler gives me the following warning:

warning: value assigned to `foo` is never read
 --> src\main.rs:2:6
  |
2 |     let mut foo = String::new();
  |         ^^^^^^^
  |
  = note: #[warn(unused_assignments)] on by default

This warning seems to be wrong to me. The assignment foo has been used in the println! macro. So I should not get this error. When I remove the mutable assignment as follows, I get no warning as expected:

fn main() {
	let foo = "Hi!".to_string();
	println!("{}", foo);
}

I am using rustc 1.24.1 (d3ae9a9 2018-02-27) on Windows 7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions