mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Merge #4658
4658: Fix problem with format string tokenization r=matklad a=ruabmbua Fixed by just not handling closing curlybrace escaping. Closes https://github.com/rust-analyzer/rust-analyzer/issues/4637 Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
This commit is contained in:
commit
fe6508bd78
3 changed files with 2 additions and 5 deletions
|
@ -52,6 +52,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">argument</span><span class="format_specifier">}</span><span class="string_literal">"</span>, argument = <span class="string_literal">"test"</span>); <span class="comment">// => "test"</span>
|
||||
<span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">name</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="numeric_literal">1</span>, name = <span class="numeric_literal">2</span>); <span class="comment">// => "2 1"</span>
|
||||
<span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">a</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="variable">c</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="variable">b</span><span class="format_specifier">}</span><span class="string_literal">"</span>, a=<span class="string_literal">"a"</span>, b=<span class="char_literal">'b'</span>, c=<span class="numeric_literal">3</span>); <span class="comment">// => "a 3 b"</span>
|
||||
<span class="macro">println!</span>(<span class="string_literal">"{{</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">}}"</span>, <span class="numeric_literal">2</span>); <span class="comment">// => "{2}"</span>
|
||||
<span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>);
|
||||
<span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="numeric_literal">1</span><span class="format_specifier">$</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>, <span class="numeric_literal">5</span>);
|
||||
<span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="numeric_literal">1</span><span class="format_specifier">:</span><span class="numeric_literal">0</span><span class="format_specifier">$</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="numeric_literal">5</span>, <span class="string_literal">"x"</span>);
|
||||
|
|
|
@ -218,6 +218,7 @@ fn main() {
|
|||
println!("{argument}", argument = "test"); // => "test"
|
||||
println!("{name} {}", 1, name = 2); // => "2 1"
|
||||
println!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b"
|
||||
println!("{{{}}}", 2); // => "{2}"
|
||||
println!("Hello {:5}!", "x");
|
||||
println!("Hello {:1$}!", "x", 5);
|
||||
println!("Hello {1:0$}!", 5, "x");
|
||||
|
|
|
@ -418,14 +418,9 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
|
||||
let mut cloned = chars.clone().take(2);
|
||||
let first = cloned.next().and_then(|next| next.1.as_ref().ok()).copied();
|
||||
let second = cloned.next().and_then(|next| next.1.as_ref().ok()).copied();
|
||||
if first != Some('}') {
|
||||
continue;
|
||||
}
|
||||
if second == Some('}') {
|
||||
// Escaped format end specifier, `}}`
|
||||
continue;
|
||||
}
|
||||
skip_char_and_emit(&mut chars, FormatSpecifier::Close, &mut callback);
|
||||
}
|
||||
_ => {
|
||||
|
|
Loading…
Reference in a new issue