File tree Expand file tree Collapse file tree 4 files changed +35
-12
lines changed Expand file tree Collapse file tree 4 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ version = "0.0.0"
66[lib ]
77name = " rustc_lint"
88path = " lib.rs"
9- crate-type = [" dylib" ]
9+ crate-types = [" rlib " , " dylib" ]
1010test = false
1111
1212[dependencies ]
@@ -15,3 +15,5 @@ rustc = { path = "../librustc" }
1515rustc_const_eval = { path = " ../librustc_const_eval" }
1616syntax = { path = " ../libsyntax" }
1717syntax_pos = { path = " ../libsyntax_pos" }
18+ lazy_static = " 1.0"
19+ regex = " 0.2.3"
Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ use syntax_pos::Span;
2121use rustc:: hir:: { self , PatKind } ;
2222use rustc:: hir:: intravisit:: FnKind ;
2323
24+ use regex:: Regex ;
25+
26+ lazy_static ! {
27+ static ref ALPHABETIC_UNDERSCORE : Regex = Regex :: new( "([[:alpha:]])_([[:alpha:]])" ) . unwrap( ) ;
28+ }
29+
2430#[ derive( PartialEq ) ]
2531pub enum MethodLateContext {
2632 TraitAutoImpl ,
@@ -62,20 +68,24 @@ impl NonCamelCaseTypes {
6268
6369 // start with a non-lowercase letter rather than non-uppercase
6470 // ones (some scripts don't have a concept of upper/lowercase)
65- !name. is_empty ( ) && !name. chars ( ) . next ( ) . unwrap ( ) . is_lowercase ( ) && !name. contains ( '_' )
71+ !name. is_empty ( ) && !name. chars ( ) . next ( ) . unwrap ( ) . is_lowercase ( ) &&
72+ !ALPHABETIC_UNDERSCORE . is_match ( name)
6673 }
6774
6875 fn to_camel_case ( s : & str ) -> String {
69- s. split ( '_' )
70- . flat_map ( |word| {
71- word. chars ( ) . enumerate ( ) . map ( |( i, c) | if i == 0 {
72- c. to_uppercase ( ) . collect :: < String > ( )
73- } else {
74- c. to_lowercase ( ) . collect ( )
75- } )
76- } )
77- . collect :: < Vec < _ > > ( )
78- . concat ( )
76+ let s = s. split ( '_' )
77+ . map ( |word| {
78+ word. chars ( ) . enumerate ( ) . map ( |( i, c) | if i == 0 {
79+ c. to_uppercase ( ) . collect :: < String > ( )
80+ } else {
81+ c. to_lowercase ( ) . collect ( )
82+ } )
83+ . collect :: < Vec < _ > > ( )
84+ . concat ( )
85+ } )
86+ . collect :: < Vec < _ > > ( )
87+ . join ( "_" ) ;
88+ ALPHABETIC_UNDERSCORE . replace_all ( s. as_str ( ) , "$1$2" ) . to_string ( )
7989 }
8090
8191 if !is_camel_case ( name) {
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ extern crate rustc;
4141extern crate log;
4242extern crate rustc_const_eval;
4343extern crate syntax_pos;
44+ #[ macro_use]
45+ extern crate lazy_static;
46+ extern crate regex;
4447
4548use rustc:: lint;
4649use rustc:: middle;
You can’t perform that action at this time.
0 commit comments