Skip to content

Commit

Permalink
Unify non-snake-case lints and non-uppercase statics lints
Browse files Browse the repository at this point in the history
This unifies the `non_snake_case_functions` and `uppercase_variables` lints
into one lint, `non_snake_case`. It also now checks for non-snake-case modules.
This also extends the non-camel-case types lint to check type parameters, and
merges the `non_uppercase_pattern_statics` lint into the
`non_uppercase_statics` lint.

Because the `uppercase_variables` lint is now part of the `non_snake_case`
lint, all non-snake-case variables that start with lowercase characters (such
as `fooBar`) will now trigger the `non_snake_case` lint.

New code should be updated to use the new `non_snake_case` lint instead of the
previous `non_snake_case_functions` and `uppercase_variables` lints. All use of
the `non_uppercase_pattern_statics` should be replaced with the
`non_uppercase_statics` lint. Any code that previously contained non-snake-case
module or variable names should be updated to use snake case names or disable
the `non_snake_case` lint. Any code with non-camel-case type parameters should
be changed to use camel case or disable the `non_camel_case_types` lint.

[breaking-change]
  • Loading branch information
ftxqxd committed Aug 29, 2014
1 parent bd159d3 commit de7abd8
Show file tree
Hide file tree
Showing 51 changed files with 214 additions and 176 deletions.
2 changes: 1 addition & 1 deletion src/doc/guide-ffi.md
Expand Up @@ -477,7 +477,7 @@ extern crate libc;

#[cfg(target_os = "win32", target_arch = "x86")]
#[link(name = "kernel32")]
#[allow(non_snake_case_functions)]
#[allow(non_snake_case)]
extern "stdcall" {
fn SetEnvironmentVariableA(n: *const u8, v: *const u8) -> libc::c_int;
}
Expand Down
2 changes: 1 addition & 1 deletion src/etc/unicode.py
Expand Up @@ -34,7 +34,7 @@
// NOTE: The following code was generated by "src/etc/unicode.py", do not edit directly
#![allow(missing_doc, non_uppercase_statics, non_snake_case_functions)]
#![allow(missing_doc, non_uppercase_statics, non_snake_case)]
'''

# Mapping taken from Table 12 from:
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/hash/mod.rs
Expand Up @@ -159,6 +159,7 @@ macro_rules! impl_hash_tuple(
impl<S: Writer, $($name: Hash<S>),*> Hash<S> for ($($name,)*) {
#[allow(uppercase_variables)]
#[inline]
#[allow(non_snake_case)]
fn hash(&self, state: &mut S) {
match *self {
($(ref $name,)*) => {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/char.rs
Expand Up @@ -12,7 +12,7 @@
//!
//! For more details, see ::unicode::char (a.k.a. std::char)

#![allow(non_snake_case_functions)]
#![allow(non_snake_case)]
#![doc(primitive = "char")]

use mem::transmute;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/mod.rs
Expand Up @@ -668,7 +668,7 @@ macro_rules! tuple (
() => ();
( $($name:ident,)+ ) => (
impl<$($name:Show),*> Show for ($($name,)*) {
#[allow(uppercase_variables, dead_assignment)]
#[allow(non_snake_case, dead_assignment)]
fn fmt(&self, f: &mut Formatter) -> Result {
try!(write!(f, "("));
let ($(ref $name,)*) = *self;
Expand Down
54 changes: 27 additions & 27 deletions src/libcore/str.rs
Expand Up @@ -394,9 +394,9 @@ impl NaiveSearcher {
fn next(&mut self, haystack: &[u8], needle: &[u8]) -> Option<(uint, uint)> {
while self.position + needle.len() <= haystack.len() {
if haystack.slice(self.position, self.position + needle.len()) == needle {
let matchPos = self.position;
let match_pos = self.position;
self.position += needle.len(); // add 1 for all matches
return Some((matchPos, matchPos + needle.len()));
return Some((match_pos, match_pos + needle.len()));
} else {
self.position += 1;
}
Expand All @@ -410,7 +410,7 @@ impl NaiveSearcher {
#[deriving(Clone)]
struct TwoWaySearcher {
// constants
critPos: uint,
crit_pos: uint,
period: uint,
byteset: u64,

Expand All @@ -423,32 +423,31 @@ struct TwoWaySearcher {
// Crochemore, M., Perrin, D., 1991, Two-way string-matching, Journal of the ACM 38(3):651-675.
impl TwoWaySearcher {
fn new(needle: &[u8]) -> TwoWaySearcher {
let (critPos1, period1) = TwoWaySearcher::maximal_suffix(needle, false);
let (critPos2, period2) = TwoWaySearcher::maximal_suffix(needle, true);
let (crit_pos1, period1) = TwoWaySearcher::maximal_suffix(needle, false);
let (crit_pos2, period2) = TwoWaySearcher::maximal_suffix(needle, true);

let critPos;
let crit_pos;
let period;
if critPos1 > critPos2 {
critPos = critPos1;
if crit_pos1 > crit_pos2 {
crit_pos = crit_pos1;
period = period1;
} else {
critPos = critPos2;
crit_pos = crit_pos2;
period = period2;
}

let byteset = needle.iter()
.fold(0, |a, &b| (1 << ((b & 0x3f) as uint)) | a);


// The logic here (calculating critPos and period, the final if statement to see which
// The logic here (calculating crit_pos and period, the final if statement to see which
// period to use for the TwoWaySearcher) is essentially an implementation of the
// "small-period" function from the paper (p. 670)
//
// In the paper they check whether `needle.slice_to(critPos)` is a suffix of
// `needle.slice(critPos, critPos + period)`, which is precisely what this does
if needle.slice_to(critPos) == needle.slice(period, period + critPos) {
// In the paper they check whether `needle.slice_to(crit_pos)` is a suffix of
// `needle.slice(crit_pos, crit_pos + period)`, which is precisely what this does
if needle.slice_to(crit_pos) == needle.slice(period, period + crit_pos) {
TwoWaySearcher {
critPos: critPos,
crit_pos: crit_pos,
period: period,
byteset: byteset,

Expand All @@ -457,8 +456,8 @@ impl TwoWaySearcher {
}
} else {
TwoWaySearcher {
critPos: critPos,
period: cmp::max(critPos, needle.len() - critPos) + 1,
crit_pos: crit_pos,
period: cmp::max(crit_pos, needle.len() - crit_pos) + 1,
byteset: byteset,

position: 0,
Expand All @@ -468,7 +467,7 @@ impl TwoWaySearcher {
}

#[inline]
fn next(&mut self, haystack: &[u8], needle: &[u8], longPeriod: bool) -> Option<(uint, uint)> {
fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool) -> Option<(uint, uint)> {
'search: loop {
// Check that we have room to search in
if self.position + needle.len() > haystack.len() {
Expand All @@ -484,36 +483,37 @@ impl TwoWaySearcher {
}

// See if the right part of the needle matches
let start = if longPeriod { self.critPos } else { cmp::max(self.critPos, self.memory) };
let start = if long_period { self.crit_pos }
else { cmp::max(self.crit_pos, self.memory) };
for i in range(start, needle.len()) {
if needle[i] != haystack[self.position + i] {
self.position += i - self.critPos + 1;
if !longPeriod {
self.position += i - self.crit_pos + 1;
if !long_period {
self.memory = 0;
}
continue 'search;
}
}

// See if the left part of the needle matches
let start = if longPeriod { 0 } else { self.memory };
for i in range(start, self.critPos).rev() {
let start = if long_period { 0 } else { self.memory };
for i in range(start, self.crit_pos).rev() {
if needle[i] != haystack[self.position + i] {
self.position += self.period;
if !longPeriod {
if !long_period {
self.memory = needle.len() - self.period;
}
continue 'search;
}
}

// We have found a match!
let matchPos = self.position;
let match_pos = self.position;
self.position += needle.len(); // add self.period for all matches
if !longPeriod {
if !long_period {
self.memory = 0; // set to needle.len() - self.period for all matches
}
return Some((matchPos, matchPos + needle.len()));
return Some((match_pos, match_pos + needle.len()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/liblibc/lib.rs
Expand Up @@ -74,10 +74,10 @@
*/

#![allow(non_camel_case_types)]
#![allow(non_snake_case_functions)]
#![allow(non_snake_case)]
#![allow(non_uppercase_statics)]
#![allow(missing_doc)]
#![allow(uppercase_variables)]
#![allow(non_snake_case)]

#[cfg(test)] extern crate std;
#[cfg(test)] extern crate test;
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/mod.rs
Expand Up @@ -21,7 +21,7 @@
//! play. The only dependencies of these modules are the normal system libraries
//! that you would find on the respective platform.

#![allow(non_snake_case_functions)]
#![allow(non_snake_case)]

use libc::c_int;
use libc;
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/process.rs
Expand Up @@ -838,7 +838,7 @@ fn free_handle(_handle: *mut ()) {

#[cfg(unix)]
fn translate_status(status: c_int) -> rtio::ProcessExit {
#![allow(non_snake_case_functions)]
#![allow(non_snake_case)]
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
mod imp {
Expand Down
1 change: 1 addition & 0 deletions src/libnum/bigint.rs
Expand Up @@ -78,6 +78,7 @@ pub type DoubleBigDigit = u64;
pub static ZERO_BIG_DIGIT: BigDigit = 0;
static ZERO_VEC: [BigDigit, ..1] = [ZERO_BIG_DIGIT];

#[allow(non_snake_case)]
pub mod BigDigit {
use super::BigDigit;
use super::DoubleBigDigit;
Expand Down
2 changes: 1 addition & 1 deletion src/librbml/lib.rs
Expand Up @@ -1132,7 +1132,7 @@ mod tests {

#[cfg(test)]
mod bench {
#![allow(non_snake_case_functions)]
#![allow(non_snake_case)]
use test::Bencher;
use super::reader;

Expand Down
2 changes: 1 addition & 1 deletion src/libregex/test/bench.rs
Expand Up @@ -7,7 +7,7 @@
// <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.
#![allow(non_snake_case_functions)]
#![allow(non_snake_case)]

use std::rand::{Rng, task_rng};
use stdtest::Bencher;
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/diagnostics.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(non_snake_case)]

register_diagnostic!(E0001, r##"
This error suggests that the expression arm corresponding to the noted pattern
will never be reached as for all possible values of the expression being matched,
Expand Down

1 comment on commit de7abd8

@steveklabnik
Copy link
Member

Choose a reason for hiding this comment

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

cc #16880

Please sign in to comment.