Skip to content

Commit 58bb8f2

Browse files
committed
Check the script extension instead of script
1 parent 7910dc9 commit 58bb8f2

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,7 @@ Released 2018-09-13
24872487
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
24882488
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
24892489
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
2490+
[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents
24902491
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
24912492
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
24922493
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
@@ -2762,7 +2763,6 @@ Released 2018-09-13
27622763
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once
27632764
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
27642765
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
2765-
[`restricted_scripts`]: https://rust-lang.github.io/rust-clippy/master/index.html#restricted_scripts
27662766
[`result_map_or_into_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_or_into_option
27672767
[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn
27682768
[`result_unit_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err

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,

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
586586
derive::EXPL_IMPL_CLONE_ON_COPY,
587587
derive::UNSAFE_DERIVE_DESERIALIZE,
588588
disallowed_method::DISALLOWED_METHOD,
589+
disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS,
589590
disallowed_type::DISALLOWED_TYPE,
590591
doc::DOC_MARKDOWN,
591592
doc::MISSING_ERRORS_DOC,
@@ -890,7 +891,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
890891
regex::INVALID_REGEX,
891892
regex::TRIVIAL_REGEX,
892893
repeat_once::REPEAT_ONCE,
893-
disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS,
894894
returns::LET_AND_RETURN,
895895
returns::NEEDLESS_RETURN,
896896
self_assignment::SELF_ASSIGNMENT,
@@ -997,6 +997,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
997997
LintId::of(create_dir::CREATE_DIR),
998998
LintId::of(dbg_macro::DBG_MACRO),
999999
LintId::of(default_numeric_fallback::DEFAULT_NUMERIC_FALLBACK),
1000+
LintId::of(disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS),
10001001
LintId::of(else_if_without_else::ELSE_IF_WITHOUT_ELSE),
10011002
LintId::of(exhaustive_items::EXHAUSTIVE_ENUMS),
10021003
LintId::of(exhaustive_items::EXHAUSTIVE_STRUCTS),
@@ -1030,7 +1031,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10301031
LintId::of(panic_unimplemented::UNIMPLEMENTED),
10311032
LintId::of(panic_unimplemented::UNREACHABLE),
10321033
LintId::of(pattern_type_mismatch::PATTERN_TYPE_MISMATCH),
1033-
LintId::of(disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS),
10341034
LintId::of(shadow::SHADOW_REUSE),
10351035
LintId::of(shadow::SHADOW_SAME),
10361036
LintId::of(strings::STRING_ADD),

0 commit comments

Comments
 (0)