Skip to content

Commit 654cea6

Browse files
committed
simplify with starts/ends_with
1 parent 9f54c59 commit 654cea6

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

clippy_lints/src/struct_fields.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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;
33
use rustc_hir::{FieldDef, ItemKind, VariantData};
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -122,12 +122,8 @@ fn check_fields(cx: &LateContext<'_>, threshold: u64, fields: &[FieldDef<'_>], i
122122
fn check_struct_start(cx: &LateContext<'_>, item_name: &str, field: &FieldDef<'_>) {
123123
let item_name_snake = to_snake_case(item_name);
124124
let name = field.ident.name.as_str();
125-
let item_name_chars = item_name_snake.chars().count();
126125

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) {
131127
span_lint_hir(
132128
cx,
133129
STRUCT_FIELD_NAMES,
@@ -141,9 +137,8 @@ fn check_struct_start(cx: &LateContext<'_>, item_name: &str, field: &FieldDef<'_
141137
fn check_struct_end(cx: &LateContext<'_>, item_name: &str, field: &FieldDef<'_>) {
142138
let item_name_snake = to_snake_case(item_name);
143139
let name = field.ident.name.as_str();
144-
let item_name_chars = item_name_snake.chars().count();
145140

146-
if count_match_end(&item_name_snake, name).char_count == item_name_chars {
141+
if name.ends_with(&item_name_snake) {
147142
span_lint_hir(
148143
cx,
149144
STRUCT_FIELD_NAMES,

0 commit comments

Comments
 (0)