mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 12:32:10 +01:00
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.
This commit is contained in:
1 parent
a9cd54e67b
commit
ccaf31d4c9
4 files changed
+18
-2
No files matched your search
Generated
+1
@@ -3125,6 +3125,7 @@ name = "craft-testkit"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rustix 1.1.5",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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#"
|
||||
|
||||
Reference in new issue
Block a user