diff options
| -rw-r--r-- | src/Cargo.lock | 8 | ||||
| -rw-r--r-- | src/librustc_lint/Cargo.toml | 4 | ||||
| -rw-r--r-- | src/librustc_lint/bad_style.rs | 32 | ||||
| -rw-r--r-- | src/librustc_lint/lib.rs | 3 |
4 files changed, 35 insertions, 12 deletions
diff --git a/src/Cargo.lock b/src/Cargo.lock index c22187ee13e..26b70f63d65 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -968,6 +968,11 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "lazy_static" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "lazycell" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1863,7 +1868,9 @@ dependencies = [ name = "rustc_lint" version = "0.0.0" dependencies = [ + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_const_eval 0.0.0", "syntax 0.0.0", @@ -2813,6 +2820,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kuchiki 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e03098e8e719c92b7794515dfd5c1724e2b12f5ce1788e61cfa4663f82eba8d8" "checksum languageserver-types 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "773e175c945800aeea4c21c04090bcb9db987b1a566ad9c6f569972299950e3e" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" +"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum lazycell 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3b585b7a6811fb03aa10e74b278a0f00f8dd9b45dc681f148bb29fa5cb61859b" "checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0" "checksum libgit2-sys 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "6f74b4959cef96898f5123148724fc7dee043b9a6b99f219d948851bfbe53cb2" diff --git a/src/librustc_lint/Cargo.toml b/src/librustc_lint/Cargo.toml index cebf52d5af7..2cc1827f518 100644 --- a/src/librustc_lint/Cargo.toml +++ b/src/librustc_lint/Cargo.toml @@ -6,7 +6,7 @@ version = "0.0.0" [lib] name = "rustc_lint" path = "lib.rs" -crate-type = ["dylib"] +crate-types = ["rlib", "dylib"] test = false [dependencies] @@ -15,3 +15,5 @@ rustc = { path = "../librustc" } rustc_const_eval = { path = "../librustc_const_eval" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } +lazy_static = "1.0" +regex = "0.2.3" diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index d14a6943fc1..09194d5c7c4 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -21,6 +21,12 @@ use syntax_pos::Span; use rustc::hir::{self, PatKind}; use rustc::hir::intravisit::FnKind; +use regex::Regex; + +lazy_static! { + static ref ALPHABETIC_UNDERSCORE: Regex = Regex::new("([[:alpha:]])_([[:alpha:]])").unwrap(); +} + #[derive(PartialEq)] pub enum MethodLateContext { TraitAutoImpl, @@ -62,20 +68,24 @@ impl NonCamelCaseTypes { // start with a non-lowercase letter rather than non-uppercase // ones (some scripts don't have a concept of upper/lowercase) - !name.is_empty() && !name.chars().next().unwrap().is_lowercase() && !name.contains('_') + !name.is_empty() && !name.chars().next().unwrap().is_lowercase() && + !ALPHABETIC_UNDERSCORE.is_match(name) } fn to_camel_case(s: &str) -> String { - s.split('_') - .flat_map(|word| { - word.chars().enumerate().map(|(i, c)| if i == 0 { - c.to_uppercase().collect::<String>() - } else { - c.to_lowercase().collect() - }) - }) - .collect::<Vec<_>>() - .concat() + let s = s.split('_') + .map(|word| { + word.chars().enumerate().map(|(i, c)| if i == 0 { + c.to_uppercase().collect::<String>() + } else { + c.to_lowercase().collect() + }) + .collect::<Vec<_>>() + .concat() + }) + .collect::<Vec<_>>() + .join("_"); + ALPHABETIC_UNDERSCORE.replace_all(s.as_str(), "$1$2").to_string() } if !is_camel_case(name) { diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 8b41dd62742..d285ac91e9f 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -41,6 +41,9 @@ extern crate rustc; extern crate log; extern crate rustc_const_eval; extern crate syntax_pos; +#[macro_use] +extern crate lazy_static; +extern crate regex; use rustc::lint; use rustc::middle; |
