Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions clippy_lints/src/disallowed_script_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
),
);
}
}
}
Expand Down