Skip to content

Commit e7f2952

Browse files
committed
Auto merge of rust-lang#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
2 parents 885f97e + ac939ad commit e7f2952

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

clippy_lints/src/disallowed_script_idents.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,25 @@ impl EarlyLintPass for DisallowedScriptIdents {
8282
// Note: `symbol.as_str()` is an expensive operation, thus should not be called
8383
// more than once for a single symbol.
8484
let symbol_str = symbol.as_str();
85-
if symbol_str.is_ascii() {
86-
continue;
87-
}
8885

89-
for c in symbol_str.chars() {
90-
// We want to iterate through all the scripts associated with this character
91-
// and check whether at least of one scripts is in the whitelist.
92-
let forbidden_script = c
93-
.script_extension()
94-
.iter()
95-
.find(|script| !self.whitelist.contains(script));
96-
if let Some(script) = forbidden_script {
97-
span_lint(
98-
cx,
99-
DISALLOWED_SCRIPT_IDENTS,
100-
span,
101-
format!(
102-
"identifier `{symbol_str}` has a Unicode script that is not allowed by configuration: {}",
103-
script.full_name()
104-
),
105-
);
106-
// We don't want to spawn warning multiple times over a single identifier.
107-
break;
108-
}
86+
// Check if any character in the symbol is not part of any allowed script.
87+
// Fast path for ascii-only idents.
88+
if !symbol_str.is_ascii()
89+
&& let Some(script) = symbol_str.chars().find_map(|c| {
90+
c.script_extension()
91+
.iter()
92+
.find(|script| !self.whitelist.contains(script))
93+
})
94+
{
95+
span_lint(
96+
cx,
97+
DISALLOWED_SCRIPT_IDENTS,
98+
span,
99+
format!(
100+
"identifier `{symbol_str}` has a Unicode script that is not allowed by configuration: {}",
101+
script.full_name()
102+
),
103+
);
109104
}
110105
}
111106
}

0 commit comments

Comments
 (0)