From ccaf31d4c98fe4018231ececd34bfb59e6d9fb55 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 20:17:01 -0800 Subject: [PATCH] craft-testkit: guards read identifiers that hold combining marks The guards' lexer split an identifier at a nonspacing mark such as U+0301, so `use std::time as t\u{301};` bound `t` and a later `t\u{301}::Instant::now()` was not reported. Identifiers now follow the Unicode XID_Start and XID_Continue properties, as rustc reads them, through the unicode-ident crate that the workspace already locks. --- Cargo.lock | 1 + crates/testkit/Cargo.toml | 1 + crates/testkit/src/guards.rs | 7 +++++-- crates/testkit/tests/guards.rs | 11 +++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3c4e0343a..f4957a3a8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3125,6 +3125,7 @@ name = "craft-testkit" version = "0.1.0" dependencies = [ "rustix 1.1.5", + "unicode-ident", ] [[package]] diff --git a/crates/testkit/Cargo.toml b/crates/testkit/Cargo.toml index bfb89fb742..5e58b0168b 100644 --- a/crates/testkit/Cargo.toml +++ b/crates/testkit/Cargo.toml @@ -9,6 +9,7 @@ description = "Source-level platform regression guards and verification utilitie publish = false [dependencies] +unicode-ident = "1" [target.'cfg(unix)'.dependencies] rustix = { version = "1.1", default-features = false, features = ["std", "fs"] } diff --git a/crates/testkit/src/guards.rs b/crates/testkit/src/guards.rs index 69c6b8aa3b..c9296d18d8 100644 --- a/crates/testkit/src/guards.rs +++ b/crates/testkit/src/guards.rs @@ -151,12 +151,15 @@ impl Token { } } +/// Whether `c` can start a Rust identifier: `_` or a character with the Unicode `XID_Start` property. fn is_ident_start(c: char) -> bool { - c == '_' || c.is_alphabetic() + c == '_' || unicode_ident::is_xid_start(c) } +/// Whether `c` can continue a Rust identifier: a character with the Unicode `XID_Continue` property, which +/// includes `_`, digits and combining marks such as U+0301. fn is_ident_continue(c: char) -> bool { - c == '_' || c.is_alphanumeric() + unicode_ident::is_xid_continue(c) } /// Split Rust source into tokens with 1-based line numbers. diff --git a/crates/testkit/tests/guards.rs b/crates/testkit/tests/guards.rs index 251adaa05b..725fb1f376 100644 --- a/crates/testkit/tests/guards.rs +++ b/crates/testkit/tests/guards.rs @@ -1405,6 +1405,17 @@ fn a_long_name_shared_by_many_use_leaves_is_read_without_copying_it_to_each() { assert!(predefined_quit([("src/wide.rs", source.as_str())]).is_empty()); } +#[test] +fn guards_read_names_that_hold_combining_marks() { + // `t` with U+0301 (a nonspacing mark) and Devanagari `ka` with U+093E (a spacing mark) are each one + // identifier, as rustc reads them. + let time = "use std::time as t\u{301};\nuse std::time as \u{915}\u{93E};\nfn run() {\n let a = t\u{301}::Instant::now();\n let b = \u{915}\u{93E}::Instant::now();\n}\n"; + assert_eq!(lines(&std_instant([("src/run.rs", time)])), vec![4, 5]); + + let menu = "use muda::{PredefinedMenuItem as Ite\u{301}m};\nfn menu() {\n let a = Ite\u{301}m::quit(None);\n}\n"; + assert_eq!(lines(&predefined_quit([("src/menu.rs", menu)])), vec![3]); +} + #[test] fn std_instant_reports_a_grouped_import_through_a_long_alias_of_std_time() { let source = r#"