Skip to content

Commit 132d333

Browse files
authored
Merge pull request #20963 from ShoyuVanilla/lit-suffix
fix: Expand literals with wrong suffixes into `LitKind::Err`
2 parents 5b884c4 + a0217d8 commit 132d333

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
<style>
3+
body { margin: 0; }
4+
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5+
6+
.lifetime { color: #DFAF8F; font-style: italic; }
7+
.label { color: #DFAF8F; font-style: italic; }
8+
.comment { color: #7F9F7F; }
9+
.documentation { color: #629755; }
10+
.intra_doc_link { font-style: italic; }
11+
.injected { opacity: 0.65 ; }
12+
.struct, .enum { color: #7CB8BB; }
13+
.enum_variant { color: #BDE0F3; }
14+
.string_literal { color: #CC9393; }
15+
.field { color: #94BFF3; }
16+
.function { color: #93E0E3; }
17+
.parameter { color: #94BFF3; }
18+
.text { color: #DCDCCC; }
19+
.type { color: #7CB8BB; }
20+
.builtin_type { color: #8CD0D3; }
21+
.type_param { color: #DFAF8F; }
22+
.attribute { color: #94BFF3; }
23+
.numeric_literal { color: #BFEBBF; }
24+
.bool_literal { color: #BFE6EB; }
25+
.macro { color: #94BFF3; }
26+
.proc_macro { color: #94BFF3; text-decoration: underline; }
27+
.derive { color: #94BFF3; font-style: italic; }
28+
.module { color: #AFD8AF; }
29+
.value_param { color: #DCDCCC; }
30+
.variable { color: #DCDCCC; }
31+
.format_specifier { color: #CC696B; }
32+
.mutable { text-decoration: underline; }
33+
.escape_sequence { color: #94BFF3; }
34+
.keyword { color: #F0DFAF; font-weight: bold; }
35+
.control { font-style: italic; }
36+
.reference { font-style: italic; font-weight: bold; }
37+
.const { font-weight: bolder; }
38+
.unsafe { color: #BC8383; }
39+
40+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
41+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
42+
</style>
43+
<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
44+
<span class="macro default_library library">format_args</span><span class="macro_bang">!</span><span class="parenthesis">(</span>"{} {}, {} (подозрение на спам: {:.2}%)"б<span class="parenthesis">)</span><span class="semicolon">;</span>
45+
<span class="brace">}</span></code></pre>

crates/ide/src/syntax_highlighting/tests.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,3 +1497,17 @@ fn main() {
14971497
false,
14981498
);
14991499
}
1500+
1501+
#[test]
1502+
fn regression_20952() {
1503+
check_highlighting(
1504+
r#"
1505+
//- minicore: fmt
1506+
fn main() {
1507+
format_args!("{} {}, {} (подозрение на спам: {:.2}%)"б);
1508+
}
1509+
"#,
1510+
expect_file!["./test_data/regression_20952.html"],
1511+
false,
1512+
);
1513+
}

crates/proc-macro-srv/src/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn test_fn_like_macro_clone_literals() {
326326
PUNCH , [alone] 1
327327
LITERAL Str hello bridge 1
328328
PUNCH , [alone] 1
329-
LITERAL Str suffixedsuffix 1
329+
LITERAL Err(()) "suffixed"suffix 1
330330
PUNCH , [alone] 1
331331
LITERAL StrRaw(2) raw 1
332332
PUNCH , [alone] 1
@@ -372,7 +372,7 @@ fn test_fn_like_macro_clone_literals() {
372372
PUNCH , [alone] 42:Root[0000, 0]@27..28#ROOT2024
373373
LITERAL Str hello bridge 42:Root[0000, 0]@29..43#ROOT2024
374374
PUNCH , [alone] 42:Root[0000, 0]@43..44#ROOT2024
375-
LITERAL Str suffixedsuffix 42:Root[0000, 0]@45..61#ROOT2024
375+
LITERAL Err(()) "suffixed"suffix 42:Root[0000, 0]@45..61#ROOT2024
376376
PUNCH , [alone] 42:Root[0000, 0]@61..62#ROOT2024
377377
LITERAL StrRaw(2) raw 42:Root[0000, 0]@63..73#ROOT2024
378378
PUNCH , [alone] 42:Root[0000, 0]@73..74#ROOT2024

crates/tt/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,15 @@ where
622622
let lit = &lit[start_offset..lit.len() - end_offset];
623623
let suffix = match suffix {
624624
"" | "_" => None,
625+
// ill-suffixed literals
626+
_ if !matches!(kind, LitKind::Integer | LitKind::Float | LitKind::Err(_)) => {
627+
return Literal {
628+
span,
629+
symbol: Symbol::intern(text),
630+
kind: LitKind::Err(()),
631+
suffix: None,
632+
};
633+
}
625634
suffix => Some(Symbol::intern(suffix)),
626635
};
627636

0 commit comments

Comments
 (0)