Skip to content

Missing warning about removing mut qualifier? #50321

Closed
@djc

Description

@djc

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions