Skip to content

Commit

Permalink
Check the script extension instead of script
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Jun 26, 2021
1 parent 7910dc9 commit 3b46f95
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions clippy_lints/src/disallowed_script_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,32 @@ impl EarlyLintPass for DisallowedScriptIdents {
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint/src/non_ascii_idents.rs

let check_disallowed_script_idents = cx.builder.lint_level(DISALLOWED_SCRIPT_IDENTS).0 != Level::Allow;

if !check_disallowed_script_idents {
return;
}

let symbols = cx.sess.parse_sess.symbol_gallery.symbols.lock();

// Sort by `Span` so that error messages make sense with respect to the
// order of identifier locations in the code.
let mut symbols: Vec<_> = symbols.iter().collect();
symbols.sort_unstable_by_key(|k| k.1);

for (symbol, &span) in &symbols {
// 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() {
let script = c.script();
if !self.whitelist.contains(&script) {
// 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,
Expand Down

0 comments on commit 3b46f95

Please sign in to comment.