-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.

Description
(sorry if this is an duplicate or the wrong repo 😇 )
fn main() {
let mut name;
name = format!("foo{}", "bar");
dbg!(name);
}
Current behavior:
no warning
Expected behavior:
warning: variable does not need to be mutable
--> src/main.rs:2:9
|
2 | let mut name;
| ----^
| |
| help: remove this `mut`
|
= note: #[warn(unused_mut)] on by default
The variable clearly doesn't need to be mutable, still, nothing is detected and no warning is emitted.
Rust 1.35.0
(Using the playground, also in 1.37.0-nightly
(2019-05-31 7840a0b753a065a41999
))
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
czipperz commentedon Jun 1, 2019
The warning appears again if you switch to 2015 edition. Huh. Nice catch!
czipperz commentedon Jun 1, 2019
I found that Stable 2015 edition produces the warning and everything else doesn't.
jonas-schievink commentedon Jun 1, 2019
cc @matthewjasper (likely caused by NLL migrate mode, which was enabled in #59114 for the 2015 edition)
matthewjasper commentedon Jun 1, 2019
Yes, looks like another nll bug. If someone wants to have a go at this, the issue is that we are treating DropAndReplace differently to Assign for the purposes of this lint.
czipperz commentedon Jun 1, 2019
I can try doing it I just don't know here to begin.
jonas-schievink commentedon Jun 1, 2019
@czipperz I don't know this code too well, but take a look at
src/librustc_mir/borrow_check/used_muts.rs
. The first thing I'd try is adding a case forDropAndReplace
to the match invisit_statement
that mirrors what's done forAssign
.czipperz commentedon Jun 1, 2019
Makes sense thank you. I was looking at librustc_lint and couldn't find anything.
[-]"variable does not need to be mutable" no detected[/-][+]"variable does not need to be mutable" not detected[/+]Rollup merge of rust-lang#61446 - czipperz:nll-unused_mut, r=matthewj…
Rollup merge of rust-lang#61446 - czipperz:nll-unused_mut, r=matthewj…
Rollup merge of rust-lang#61446 - czipperz:nll-unused_mut, r=matthewj…