diff options
| author | P1start <rewi-github@whanau.org> | 2014-09-13 13:59:15 +1200 | 
|---|---|---|
| committer | P1start <rewi-github@whanau.org> | 2014-10-03 20:39:56 +1300 | 
| commit | 45044124e46bbfd1ab9869ffce71259ae93866ff (patch) | |
| tree | 61c40510ab81a455ad14742397b4a605444d072a | |
| parent | 333592edde810324c9730a89372fa5164d10871d (diff) | |
| download | rust-45044124e46bbfd1ab9869ffce71259ae93866ff.tar.gz rust-45044124e46bbfd1ab9869ffce71259ae93866ff.zip  | |
Improve the `non_snake_case` lint to give better suggestions
| -rw-r--r-- | src/librustc/lint/builtin.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-non-snake-case-functions.rs | 5 | 
2 files changed, 9 insertions, 2 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 8ffda8bd827..ea647fda848 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -871,13 +871,17 @@ impl NonSnakeCase { fn to_snake_case(str: &str) -> String { let mut words = vec![]; for s in str.split('_') { + let mut last_upper = false; let mut buf = String::new(); if s.is_empty() { continue; } for ch in s.chars() { - if !buf.is_empty() && buf.as_slice() != "'" && ch.is_uppercase() { + if !buf.is_empty() && buf.as_slice() != "'" + && ch.is_uppercase() + && !last_upper { words.push(buf); buf = String::new(); } + last_upper = ch.is_uppercase(); buf.push_char(ch.to_lowercase()); } words.push(buf); diff --git a/src/test/compile-fail/lint-non-snake-case-functions.rs b/src/test/compile-fail/lint-non-snake-case-functions.rs index ccbe1f006e3..6cfdc6ad90b 100644 --- a/src/test/compile-fail/lint-non-snake-case-functions.rs +++ b/src/test/compile-fail/lint-non-snake-case-functions.rs @@ -23,11 +23,14 @@ impl Foo { pub fn xyZ(&mut self) {} //~^ ERROR method `xyZ` should have a snake case name such as `xy_z` + + fn render_HTML() {} + //~^ ERROR method `render_HTML` should have a snake case name such as `render_html` } trait X { fn ABC(); - //~^ ERROR trait method `ABC` should have a snake case name such as `a_b_c` + //~^ ERROR trait method `ABC` should have a snake case name such as `abc` fn a_b_C(&self) {} //~^ ERROR trait method `a_b_C` should have a snake case name such as `a_b_c`  | 
