From a0217d8311d1bf17cd7e3243da9f91230e65d783 Mon Sep 17 00:00:00 2001 From: Shoyu Vanilla Date: Tue, 4 Nov 2025 00:36:27 +0900 Subject: [PATCH] fix: Expand literals with wrong suffixes into `LitKind::Err` --- .../test_data/regression_20952.html | 45 +++++++++++++++++++ crates/ide/src/syntax_highlighting/tests.rs | 14 ++++++ crates/proc-macro-srv/src/tests/mod.rs | 4 +- crates/tt/src/lib.rs | 9 ++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 crates/ide/src/syntax_highlighting/test_data/regression_20952.html diff --git a/crates/ide/src/syntax_highlighting/test_data/regression_20952.html b/crates/ide/src/syntax_highlighting/test_data/regression_20952.html new file mode 100644 index 0000000000..2c0250c6d4 --- /dev/null +++ b/crates/ide/src/syntax_highlighting/test_data/regression_20952.html @@ -0,0 +1,45 @@ + + +
fn main() {
+    format_args!("{} {}, {} (подозрение на спам: {:.2}%)"б);
+}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 4e84127c29..58c613ef7c 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -1497,3 +1497,17 @@ fn main() { false, ); } + +#[test] +fn regression_20952() { + check_highlighting( + r#" +//- minicore: fmt +fn main() { + format_args!("{} {}, {} (подозрение на спам: {:.2}%)"б); +} +"#, + expect_file!["./test_data/regression_20952.html"], + false, + ); +} diff --git a/crates/proc-macro-srv/src/tests/mod.rs b/crates/proc-macro-srv/src/tests/mod.rs index 08495f50bf..d4f9976c92 100644 --- a/crates/proc-macro-srv/src/tests/mod.rs +++ b/crates/proc-macro-srv/src/tests/mod.rs @@ -326,7 +326,7 @@ fn test_fn_like_macro_clone_literals() { PUNCH , [alone] 1 LITERAL Str hello bridge 1 PUNCH , [alone] 1 - LITERAL Str suffixedsuffix 1 + LITERAL Err(()) "suffixed"suffix 1 PUNCH , [alone] 1 LITERAL StrRaw(2) raw 1 PUNCH , [alone] 1 @@ -372,7 +372,7 @@ fn test_fn_like_macro_clone_literals() { PUNCH , [alone] 42:Root[0000, 0]@27..28#ROOT2024 LITERAL Str hello bridge 42:Root[0000, 0]@29..43#ROOT2024 PUNCH , [alone] 42:Root[0000, 0]@43..44#ROOT2024 - LITERAL Str suffixedsuffix 42:Root[0000, 0]@45..61#ROOT2024 + LITERAL Err(()) "suffixed"suffix 42:Root[0000, 0]@45..61#ROOT2024 PUNCH , [alone] 42:Root[0000, 0]@61..62#ROOT2024 LITERAL StrRaw(2) raw 42:Root[0000, 0]@63..73#ROOT2024 PUNCH , [alone] 42:Root[0000, 0]@73..74#ROOT2024 diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs index 243a27b83b..f9a547f611 100644 --- a/crates/tt/src/lib.rs +++ b/crates/tt/src/lib.rs @@ -622,6 +622,15 @@ where let lit = &lit[start_offset..lit.len() - end_offset]; let suffix = match suffix { "" | "_" => None, + // ill-suffixed literals + _ if !matches!(kind, LitKind::Integer | LitKind::Float | LitKind::Err(_)) => { + return Literal { + span, + symbol: Symbol::intern(text), + kind: LitKind::Err(()), + suffix: None, + }; + } suffix => Some(Symbol::intern(suffix)), };