diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index f13814527cdfd..7fde4203ca0ff 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -938,10 +938,9 @@ pub struct NonSnakeCase; impl NonSnakeCase { fn check_snake_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) { - fn is_snake_case(ident: ast::Ident) -> bool { - let ident = token::get_ident(ident); - if ident.get().is_empty() { return true; } - let ident = ident.get().trim_left_matches('\''); + fn is_snake_case(ident: &str) -> bool { + if ident.is_empty() { return true; } + let ident = ident.trim_left_matches('\''); let ident = ident.trim_matches('_'); let mut allow_underscore = true; @@ -978,10 +977,16 @@ impl NonSnakeCase { let s = token::get_ident(ident); - if !is_snake_case(ident) { - cx.span_lint(NON_SNAKE_CASE, span, - &format!("{} `{}` should have a snake case name such as `{}`", - sort, s, to_snake_case(s.get()))[]); + if !is_snake_case(s.get()) { + let snaked = to_snake_case(s.get()); + if is_snake_case(&*snaked) { + cx.span_lint(NON_SNAKE_CASE, span, + &format!("{} `{}` should have a snake case name such as `{}`", + sort, s, snaked)[]); + } else { + cx.span_lint(NON_SNAKE_CASE, span, + &format!("{} `{}` should have a snake case name", sort, s)[]); + } } } } 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 6cfdc6ad90b91..a10e95119a62f 100644 --- a/src/test/compile-fail/lint-non-snake-case-functions.rs +++ b/src/test/compile-fail/lint-non-snake-case-functions.rs @@ -10,6 +10,7 @@ #![deny(non_snake_case)] #![allow(dead_code)] +#![feature(non_ascii_idents)] struct Foo; @@ -26,6 +27,9 @@ impl Foo { fn render_HTML() {} //~^ ERROR method `render_HTML` should have a snake case name such as `render_html` + + fn を() {} + //~^ ERROR method `を` should have a snake case name } trait X { @@ -37,6 +41,9 @@ trait X { fn something__else(&mut self); //~^ ERROR trait method `something__else` should have a snake case name such as `something_else` + + fn あ() {} + //~^ ERROR method `あ` should have a snake case name } impl X for Foo { @@ -51,4 +58,7 @@ fn Cookie() {} pub fn bi_S_Cuit() {} //~^ ERROR function `bi_S_Cuit` should have a snake case name such as `bi_s_cuit` +pub fn お() {} +//~^ ERROR function `お` should have a snake case name + fn main() { }