Fix disallowed_script_idents FP on identifiers with _ (#15123)

Closes rust-lang/rust-clippy#15116

The cause for this issue is that `_` belongs to the `Common` catagory in
unicode instead of `Latin` like other ASCII alphabets. Since ASCII
characters are always allowed, I just added an extra `is_ascii()` check
to ensure this.

changelog: [`disallowed_script_idents`] fix FP on identifiers with `_`
This commit is contained in:
dswij 2025-06-28 08:48:07 +00:00 committed by GitHub
commit 428208eb9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

@ -89,6 +89,10 @@ impl EarlyLintPass for DisallowedScriptIdents {
// Fast path for ascii-only idents.
if !symbol_str.is_ascii()
&& let Some(script) = symbol_str.chars().find_map(|c| {
if c.is_ascii() {
return None;
}
c.script_extension()
.iter()
.find(|script| !self.whitelist.contains(script))

View file

@ -15,3 +15,17 @@ fn main() {
let = 10;
//~^ disallowed_script_idents
}
fn issue15116() {
const ÄÖÜ: u8 = 0;
const _ÄÖÜ: u8 = 0;
const Ä_ÖÜ: u8 = 0;
const ÄÖ: u8 = 0;
const ÄÖÜ_: u8 = 0;
let äöüß = 1;
let _äöüß = 1;
let ä_öüß = 1;
let äö_üß = 1;
let äöü = 1;
let äöüß_ = 1;
}