mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
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
This commit is contained in:
commit
e7f2952f7e
1 changed files with 18 additions and 23 deletions
|
@ -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()
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue