Skip to content

Commit 3b46f95

Browse files
committed
Check the script extension instead of script
1 parent 7910dc9 commit 3b46f95

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clippy_lints/src/disallowed_script_idents.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,32 @@ impl EarlyLintPass for DisallowedScriptIdents {
6565
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint/src/non_ascii_idents.rs
6666

6767
let check_disallowed_script_idents = cx.builder.lint_level(DISALLOWED_SCRIPT_IDENTS).0 != Level::Allow;
68-
6968
if !check_disallowed_script_idents {
7069
return;
7170
}
7271

7372
let symbols = cx.sess.parse_sess.symbol_gallery.symbols.lock();
74-
7573
// Sort by `Span` so that error messages make sense with respect to the
7674
// order of identifier locations in the code.
7775
let mut symbols: Vec<_> = symbols.iter().collect();
7876
symbols.sort_unstable_by_key(|k| k.1);
7977

8078
for (symbol, &span) in &symbols {
79+
// Note: `symbol.as_str()` is an expensive operation, thus should not be called
80+
// more than once for a single symbol.
8181
let symbol_str = symbol.as_str();
8282
if symbol_str.is_ascii() {
8383
continue;
8484
}
8585

8686
for c in symbol_str.chars() {
87-
let script = c.script();
88-
if !self.whitelist.contains(&script) {
87+
// We want to iterate through all the scripts associated with this character
88+
// and check whether at least of one scripts is in the whitelist.
89+
let forbidden_script = c
90+
.script_extension()
91+
.iter()
92+
.find(|script| !self.whitelist.contains(script));
93+
if let Some(script) = forbidden_script {
8994
span_lint(
9095
cx,
9196
DISALLOWED_SCRIPT_IDENTS,

0 commit comments

Comments
 (0)