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

Lint against lowercase static mut #37162

Merged
merged 3 commits into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_lint/bad_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,12 @@ impl LintPass for NonUpperCaseGlobals {
impl LateLintPass for NonUpperCaseGlobals {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
match it.node {
// only check static constants
hir::ItemStatic(_, hir::MutImmutable, _) => {
NonUpperCaseGlobals::check_upper_case(cx, "static constant", it.name, it.span);
}
hir::ItemStatic(_, hir::MutMutable, _) => {
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span);
}
Copy link
Contributor

@jseyfried jseyfried Oct 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the above two arms could be merged into a single arm:

    hir::ItemStatic(..) => {
        NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span);
    }

hir::ItemConst(..) => {
NonUpperCaseGlobals::check_upper_case(cx, "constant", it.name, it.span);
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/lint-non-uppercase-statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@

static foo: isize = 1; //~ ERROR static constant `foo` should have an upper case name such as `FOO`

static mut bar: isize = 1;
//~^ ERROR static variable `bar` should have an upper case name such as `BAR`

fn main() { }

This file was deleted.