Skip to content

Commit 6236852

Browse files
committed
Improve the non_snake_case lint to give better suggestions
1 parent 39f9cd1 commit 6236852

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/librustc/lint/builtin.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,13 +887,17 @@ impl NonSnakeCase {
887887
fn to_snake_case(str: &str) -> String {
888888
let mut words = vec![];
889889
for s in str.split('_') {
890+
let mut last_upper = false;
890891
let mut buf = String::new();
891892
if s.is_empty() { continue; }
892893
for ch in s.chars() {
893-
if !buf.is_empty() && buf.as_slice() != "'" && ch.is_uppercase() {
894+
if !buf.is_empty() && buf.as_slice() != "'"
895+
&& ch.is_uppercase()
896+
&& !last_upper {
894897
words.push(buf);
895898
buf = String::new();
896899
}
900+
last_upper = ch.is_uppercase();
897901
buf.push_char(ch.to_lowercase());
898902
}
899903
words.push(buf);

src/test/compile-fail/lint-non-snake-case-functions.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ impl Foo {
2323

2424
pub fn xyZ(&mut self) {}
2525
//~^ ERROR method `xyZ` should have a snake case name such as `xy_z`
26+
27+
fn render_HTML() {}
28+
//~^ ERROR method `render_HTML` should have a snake case name such as `render_html`
2629
}
2730

2831
trait X {
2932
fn ABC();
30-
//~^ ERROR trait method `ABC` should have a snake case name such as `a_b_c`
33+
//~^ ERROR trait method `ABC` should have a snake case name such as `abc`
3134

3235
fn a_b_C(&self) {}
3336
//~^ ERROR trait method `a_b_C` should have a snake case name such as `a_b_c`

0 commit comments

Comments
 (0)