1
1
use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_hir} ;
2
- use clippy_utils:: str_utils:: { count_match_end , count_match_start , to_snake_case} ;
2
+ use clippy_utils:: str_utils:: to_snake_case;
3
3
use rustc_hir:: { FieldDef , ItemKind , VariantData } ;
4
4
use rustc_lint:: { LateContext , LateLintPass } ;
5
5
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
@@ -122,12 +122,8 @@ fn check_fields(cx: &LateContext<'_>, threshold: u64, fields: &[FieldDef<'_>], i
122
122
fn check_struct_start ( cx : & LateContext < ' _ > , item_name : & str , field : & FieldDef < ' _ > ) {
123
123
let item_name_snake = to_snake_case ( item_name) ;
124
124
let name = field. ident . name . as_str ( ) ;
125
- let item_name_chars = item_name_snake. chars ( ) . count ( ) ;
126
125
127
- if count_match_start ( & item_name_snake, name) . char_count == item_name_chars
128
- && name. chars ( ) . nth ( item_name_chars) . map_or ( false , |c| !c. is_lowercase ( ) )
129
- && name. chars ( ) . nth ( item_name_chars + 1 ) . map_or ( false , |c| !c. is_numeric ( ) )
130
- {
126
+ if name. starts_with ( & item_name_snake) {
131
127
span_lint_hir (
132
128
cx,
133
129
STRUCT_FIELD_NAMES ,
@@ -141,9 +137,8 @@ fn check_struct_start(cx: &LateContext<'_>, item_name: &str, field: &FieldDef<'_
141
137
fn check_struct_end ( cx : & LateContext < ' _ > , item_name : & str , field : & FieldDef < ' _ > ) {
142
138
let item_name_snake = to_snake_case ( item_name) ;
143
139
let name = field. ident . name . as_str ( ) ;
144
- let item_name_chars = item_name_snake. chars ( ) . count ( ) ;
145
140
146
- if count_match_end ( & item_name_snake, name ) . char_count == item_name_chars {
141
+ if name . ends_with ( & item_name_snake) {
147
142
span_lint_hir (
148
143
cx,
149
144
STRUCT_FIELD_NAMES ,
0 commit comments