Skip to content

Non-upper case constant warning misapplied in patterns #39371

Open
@rpjohnst

Description

@rpjohnst

A constant with #[allow(non_upper_case_globals)] applied still generates a warning when used in a pattern, unless the match also has the allow attribute. For example:

#[allow(non_upper_case_globals)]
mod keywords {
    pub const If: u32 = 0;
    pub const While: u32 = 1;
}

fn main() {
    use keywords::*;

    // the warning goes away with this attribute:
    // #[allow(non_upper_case_globals)]
    match 0 {
        keywords::If => println!("if"),
        While => println!("while"),
        _ => println!("<unknown>"),
    }
}

Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.I-needs-decisionIssue: In need of a decision.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