craft-testkit: read identifier characters with std only

The guards need only std, so the unicode-ident dependency is removed.
Outside literals and comments Rust allows a non-ASCII character only in
an identifier or as white space, so the lexer reads every non-ASCII
character other than white space as part of an identifier. The
left-to-right and right-to-left marks and a byte order mark are read as
white space, so `t\u{200F}::Instant::now()` is still reported.
This commit is contained in:
dotCooCoo committed 2026-11-19 20:31:49 -08:00
1 parent 2477df8c86
commit fa829e4a37
4 files changed
+19 -8

No files matched your search

Generated
-1
View File
@@ -3125,7 +3125,6 @@ name = "craft-testkit"
version = "0.1.0"
dependencies = [
"rustix 1.1.5",
"unicode-ident",
]
[[package]]
-1
View File
@@ -9,7 +9,6 @@ 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"] }
+15 -6
View File
@@ -151,15 +151,22 @@ impl Token {
}
}
/// Whether `c` can start a Rust identifier: `_` or a character with the Unicode `XID_Start` property.
/// Whether `c` can start a Rust identifier: `_`, a letter, or another non-ASCII character that is not white
/// space (see [`non_ascii_word`]).
fn is_ident_start(c: char) -> bool {
c == '_' || unicode_ident::is_xid_start(c)
c == '_' || c.is_alphabetic() || non_ascii_word(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.
/// Whether `c` can continue a Rust identifier: `_`, a letter or digit, or another non-ASCII character that is
/// not white space, such as the combining mark U+0301.
fn is_ident_continue(c: char) -> bool {
unicode_ident::is_xid_continue(c)
c == '_' || c.is_alphanumeric() || non_ascii_word(c)
}
/// Whether `c` is a non-ASCII character other than Rust's white space and the byte order mark U+FEFF. Outside
/// literals and comments, Rust allows such a character only in an identifier, so it is read as part of one.
fn non_ascii_word(c: char) -> bool {
!c.is_ascii() && !c.is_whitespace() && !matches!(c, '\u{200E}' | '\u{200F}' | '\u{FEFF}')
}
/// Split Rust source into tokens with 1-based line numbers.
@@ -181,7 +188,9 @@ fn lex_rust(code: &str) -> Vec<Token> {
if c == '\n' {
line += 1;
i += 1;
} else if c.is_whitespace() {
} else if c.is_whitespace() || matches!(c, '\u{200E}' | '\u{200F}' | '\u{FEFF}') {
// Rust also reads the left-to-right and right-to-left marks as white space, and skips a byte
// order mark at the start of a file.
i += 1;
} else if c == '/' && at(i + 1) == Some('/') {
while i < len && chars[i] != '\n' {
+4
View File
@@ -1446,6 +1446,10 @@ fn guards_read_names_that_hold_combining_marks() {
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]);
// A byte order mark and the left-to-right and right-to-left marks are not part of a name.
let marked = "\u{FEFF}use std::time::Instant;\nuse std::time as\u{200E}t;\nfn run() { t\u{200F}::Instant::now(); }\n";
assert_eq!(lines(&std_instant([("src/marked.rs", marked)])), vec![1, 3]);
}
#[test]