diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-08 10:05:09 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-08 10:05:09 +0100 |
commit | b366b98a9e8f70711eba6965817a063565009f6a (patch) | |
tree | 1a58db376d2deeea16543fc4bf287837fb7ee68e /crates/ra_syntax | |
parent | d6967762dd1fff3cfb65d481ba5a169143205c0e (diff) | |
parent | 3aaaf924cb649ecc3b1a59653f47d1735fa7cb5d (diff) |
Merge #4787
4787: Fix bug in lexer for format specifier r=matklad a=ltentrup
The `type` and `width` were not correctly distinguished.
Fixes #4696.
Co-authored-by: Leander Tentrup <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast/tokens.rs | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 04b0a4480..56378385a 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs | |||
@@ -335,16 +335,26 @@ pub trait HasFormatSpecifier: AstToken { | |||
335 | } | 335 | } |
336 | c if c == '_' || c.is_alphabetic() => { | 336 | c if c == '_' || c.is_alphabetic() => { |
337 | read_identifier(&mut chars, &mut callback); | 337 | read_identifier(&mut chars, &mut callback); |
338 | if chars.peek().and_then(|next| next.1.as_ref().ok()).copied() | 338 | // can be either width (indicated by dollar sign, or type in which case |
339 | != Some('$') | 339 | // the next sign has to be `}`) |
340 | { | 340 | let next = |
341 | continue; | 341 | chars.peek().and_then(|next| next.1.as_ref().ok()).copied(); |
342 | } | 342 | match next { |
343 | skip_char_and_emit( | 343 | Some('$') => skip_char_and_emit( |
344 | &mut chars, | 344 | &mut chars, |
345 | FormatSpecifier::DollarSign, | 345 | FormatSpecifier::DollarSign, |
346 | &mut callback, | 346 | &mut callback, |
347 | ); | 347 | ), |
348 | Some('}') => { | ||
349 | skip_char_and_emit( | ||
350 | &mut chars, | ||
351 | FormatSpecifier::Close, | ||
352 | &mut callback, | ||
353 | ); | ||
354 | continue; | ||
355 | } | ||
356 | _ => continue, | ||
357 | }; | ||
348 | } | 358 | } |
349 | _ => {} | 359 | _ => {} |
350 | } | 360 | } |
@@ -416,12 +426,11 @@ pub trait HasFormatSpecifier: AstToken { | |||
416 | } | 426 | } |
417 | } | 427 | } |
418 | 428 | ||
419 | let mut cloned = chars.clone().take(2); | 429 | if let Some((_, Ok('}'))) = chars.peek() { |
420 | let first = cloned.next().and_then(|next| next.1.as_ref().ok()).copied(); | 430 | skip_char_and_emit(&mut chars, FormatSpecifier::Close, &mut callback); |
421 | if first != Some('}') { | 431 | } else { |
422 | continue; | 432 | continue; |
423 | } | 433 | } |
424 | skip_char_and_emit(&mut chars, FormatSpecifier::Close, &mut callback); | ||
425 | } | 434 | } |
426 | _ => { | 435 | _ => { |
427 | while let Some((_, Ok(next_char))) = chars.peek() { | 436 | while let Some((_, Ok(next_char))) = chars.peek() { |