From 3da4c284f93770d299849f8dd3579865eb4b800e Mon Sep 17 00:00:00 2001 From: snowdrop4 <82846066+snowdrop4@users.noreply.github.com> Date: Mon, 25 Nov 2024 23:06:15 +0000 Subject: [PATCH] don't rely on compiler optimisation --- .../rules/pep8_naming/rules/camelcase_imported_as_constant.rs | 4 +--- .../pep8_naming/rules/constant_imported_as_non_constant.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs index e41ac229c4044..64e17bca616d6 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs @@ -54,9 +54,7 @@ pub(crate) fn camelcase_imported_as_constant( ignore_names: &IgnoreNames, ) -> Option { // Single-character names are ambiguous. It could be a class or a constant. - if asname.chars().count() == 1 { - return None; - } + asname.chars().skip(1).next()?; if helpers::is_camelcase(name) && !str::is_cased_lowercase(asname) diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs index f71c5abd634f3..132a873c857ba 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs @@ -53,9 +53,7 @@ pub(crate) fn constant_imported_as_non_constant( ignore_names: &IgnoreNames, ) -> Option { // Single-character names are ambiguous. It could be a class or a constant. - if name.chars().count() == 1 { - return None; - } + name.chars().skip(1).next()?; if str::is_cased_uppercase(name) && !str::is_cased_uppercase(asname) { // Ignore any explicitly-allowed names.