diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 8ffda8bd8275..ea647fda8482 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 ccbe1f006e30..6cfdc6ad90b9 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`