Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing warning about removing mut qualifier? #50321

Closed
djc opened this issue Apr 29, 2018 · 2 comments
Closed

Missing warning about removing mut qualifier? #50321

djc opened this issue Apr 29, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. NLL-fixed-by-NLL Bugs fixed, but only when NLL is enabled. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@djc
Copy link
Contributor

djc commented Apr 29, 2018

During work on Cargo, I found a seeming bug where the compiler doesn't warn about an unnecessary mut qualifier. This version does not warn:

fn bar<'a>(foo: &'a String) -> bool {
    foo == "foo"
}

fn main() {
    let res = {
        let mut foo = String::from("foo");
        bar(&foo)
    };
    println!("{:?}", res);
}

This version does warn:

fn bar<'a>(foo: &'a String) -> bool {
    foo == "foo"
}

fn main() {
    let mut foo = String::from("foo");
    let res = bar(&foo);
    println!("{:?}", res);
}
@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Apr 30, 2018
@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2018
@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Dec 13, 2018
@estebank
Copy link
Contributor

It warns now:

warning: variable does not need to be mutable
 --> src/main.rs:8:13
  |
8 |         let mut foo = String::from("foo");
  |             ----^^^
  |             |
  |             help: remove this `mut`
  |
  = note: #[warn(unused_mut)] on by default)

@djc
Copy link
Contributor Author

djc commented Dec 13, 2018

Yeah, I suppose this has been fixed with NLL.

@djc djc closed this as completed Dec 13, 2018
@estebank estebank added the NLL-fixed-by-NLL Bugs fixed, but only when NLL is enabled. label Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. NLL-fixed-by-NLL Bugs fixed, but only when NLL is enabled. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants