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

Non-upper case constant warning misapplied in patterns #39371

Open
rpjohnst opened this issue Jan 28, 2017 · 4 comments
Open

Non-upper case constant warning misapplied in patterns #39371

rpjohnst opened this issue Jan 28, 2017 · 4 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. I-needs-decision Issue: In need of a decision. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rpjohnst
Copy link
Contributor

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

@sfackler sfackler added A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 28, 2017
@est31
Copy link
Member

est31 commented Jan 28, 2017

The code that emits that warning links to issue #7526. One should find out what its actual purpose was and whether its still relevant today.

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. I-needs-decision Issue: In need of a decision. labels Jul 27, 2017
@mgsloan
Copy link
Contributor

mgsloan commented Sep 24, 2017

Is it sensible to have this warning at all in usages of the global? After all, the user of a library isn't really free to make this choice. How about just when the global / constant is defined? I'm encountering this for all of the constants from xlib - https://docs.rs/x11/2.15.0/x11/xlib/index.html#constants . For ease of copy+modifying (or corroding!) C code, this choice makes sense.

Note: I'm rather new to rust. So, perhaps there's a good reason for this that I don't see. From the newbie perspective this is a puzzling warning.

@valpackett
Copy link
Contributor

haha, I'm deriving a trait for an enum that uses bindgen-generated constants:

warning: constant in pattern `weston_layer_position_WESTON_LAYER_POSITION_UI` should have an upper case name such as `WESTON_LAYER_POSITION_WESTON_LAYER_POSITION_UI`        
  --> src/layer.rs:22:41                                                                                                                                                                
   |                                                                                                                                                                                    
22 | #[derive(Debug, Copy, Clone, PartialEq, Primitive)]                                                                                                                                
   |                                         ^^^^^^^^^                                                                                                                                  

I can't even put #[allow(non_upper_case_globals)] anywhere in my code :D

@Azorlogh
Copy link

When is this warning ever even needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. I-needs-decision Issue: In need of a decision. 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

8 participants