diff options
| author | bors <bors@rust-lang.org> | 2024-07-05 06:47:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-05 06:47:49 +0000 |
| commit | e7f2952f7e0ea9758e0830fb854dd6faea38c1c2 (patch) | |
| tree | ce60b929fba63f10759d4d332464fca0ecb621af | |
| parent | 885f97e2cefd1a246f47c6944afef5ffa6958426 (diff) | |
| parent | ac939ad3a1ba16a798d0b697e5b9b84f8c2b5f5d (diff) | |
Auto merge of #13047 - Jarcho:script, r=y21
Refactor `disallowed_script_idents` Minor change to use `find_map` instead of a loop. Not important, but it's easier to read. changelog: none
| -rw-r--r-- | clippy_lints/src/disallowed_script_idents.rs | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs index a995f06fb73..5ce11900adf 100644 --- a/clippy_lints/src/disallowed_script_idents.rs +++ b/clippy_lints/src/disallowed_script_idents.rs @@ -82,30 +82,25 @@ impl EarlyLintPass for DisallowedScriptIdents { // Note: `symbol.as_str()` is an expensive operation, thus should not be called // more than once for a single symbol. let symbol_str = symbol.as_str(); - if symbol_str.is_ascii() { - continue; - } - for c in symbol_str.chars() { - // We want to iterate through all the scripts associated with this character - // and check whether at least of one scripts is in the whitelist. - let forbidden_script = c - .script_extension() - .iter() - .find(|script| !self.whitelist.contains(script)); - if let Some(script) = forbidden_script { - span_lint( - cx, - DISALLOWED_SCRIPT_IDENTS, - span, - format!( - "identifier `{symbol_str}` has a Unicode script that is not allowed by configuration: {}", - script.full_name() - ), - ); - // We don't want to spawn warning multiple times over a single identifier. - break; - } + // Check if any character in the symbol is not part of any allowed script. + // Fast path for ascii-only idents. + if !symbol_str.is_ascii() + && let Some(script) = symbol_str.chars().find_map(|c| { + c.script_extension() + .iter() + .find(|script| !self.whitelist.contains(script)) + }) + { + span_lint( + cx, + DISALLOWED_SCRIPT_IDENTS, + span, + format!( + "identifier `{symbol_str}` has a Unicode script that is not allowed by configuration: {}", + script.full_name() + ), + ); } } } |
