-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Issue7526 attempt to catch non uppercase statics in match patterns #9638
Merged
bors
merged 9 commits into
rust-lang:master
from
pnkfelix:fsk-issue7526-attempt-to-catch-nonuc-statics-in-match-patterns
Oct 2, 2013
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a076fef
Add new lint: non_uppercase_pattern_statics, for #7526.
pnkfelix 9246742
Throwing in another interesting test case: There is no need to warn
pnkfelix c0599b1
Fix typo in comment.
pnkfelix e2be7ac
Expanded test to clarify that the constants *are* matching when they …
pnkfelix 8d6f4c2
Workaround conflict between all-uppercase static and NaN definition.
pnkfelix 155857f
Revise error message to use phrase "all caps" instead of "uppercase".
pnkfelix 06f4690
fix tests for check-fast.
pnkfelix 88d34ff
fix tests for check-fast.
pnkfelix 2461b31
incoporate suggestion from huonw to move code into lint.rs
pnkfelix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Issue #7526: lowercase static constants in patterns look like bindings | ||
|
||
#[deny(non_uppercase_pattern_statics)]; | ||
|
||
pub static a : int = 97; | ||
|
||
fn f() { | ||
let r = match (0,0) { | ||
(0, a) => 0, | ||
//~^ ERROR static constant in pattern should have an uppercase id | ||
(x, y) => 1 + x + y, | ||
}; | ||
assert!(r == 1); | ||
} | ||
|
||
mod m { | ||
pub static aha : int = 7; | ||
} | ||
|
||
fn g() { | ||
use m::aha; | ||
let r = match (0,0) { | ||
(0, aha) => 0, | ||
//~^ ERROR static constant in pattern should have an uppercase id | ||
(x, y) => 1 + x + y, | ||
}; | ||
assert!(r == 1); | ||
} | ||
|
||
fn main () { | ||
f(); | ||
g(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Issue #7526: lowercase static constants in patterns look like bindings | ||
|
||
// This is similar to compile-fail/match-static-const-lc, except it | ||
// shows the expected usual workaround (choosing a different name for | ||
// the static definition) and also demonstrates that one can work | ||
// around this problem locally by renaming the constant in the `use` | ||
// form to an uppercase identifier that placates the lint. | ||
|
||
#[deny(non_uppercase_pattern_statics)]; | ||
|
||
pub static A : int = 97; | ||
|
||
fn f() { | ||
let r = match (0,0) { | ||
(0, A) => 0, | ||
(x, y) => 1 + x + y, | ||
}; | ||
assert!(r == 1); | ||
let r = match (0,97) { | ||
(0, A) => 0, | ||
(x, y) => 1 + x + y, | ||
}; | ||
assert!(r == 0); | ||
} | ||
|
||
mod m { | ||
pub static aha : int = 7; | ||
} | ||
|
||
fn g() { | ||
use AHA = m::aha; | ||
let r = match (0,0) { | ||
(0, AHA) => 0, | ||
(x, y) => 1 + x + y, | ||
}; | ||
assert!(r == 1); | ||
let r = match (0,7) { | ||
(0, AHA) => 0, | ||
(x, y) => 1 + x + y, | ||
}; | ||
assert!(r == 0); | ||
} | ||
|
||
fn h() { | ||
let r = match (0,0) { | ||
(0, m::aha) => 0, | ||
(x, y) => 1 + x + y, | ||
}; | ||
assert!(r == 1); | ||
let r = match (0,7) { | ||
(0, m::aha) => 0, | ||
(x, y) => 1 + x + y, | ||
}; | ||
assert!(r == 0); | ||
} | ||
|
||
fn main () { | ||
f(); | ||
g(); | ||
h(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think that constants of the form
CamelCase
are probably not local variables, but I suppose that thenon_uppercase_statics
lint does this same check, so oh well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I thought about just looking at the first character alone, but I don't see the harm in nudging people towards the all-caps convention...