diff options
Diffstat (limited to 'libgrust/libformat_parser/generic_format_parser/src/lib.rs')
| -rw-r--r-- | libgrust/libformat_parser/generic_format_parser/src/lib.rs | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/libgrust/libformat_parser/generic_format_parser/src/lib.rs b/libgrust/libformat_parser/generic_format_parser/src/lib.rs index ed3d8577bef..e255bf16908 100644 --- a/libgrust/libformat_parser/generic_format_parser/src/lib.rs +++ b/libgrust/libformat_parser/generic_format_parser/src/lib.rs @@ -505,7 +505,7 @@ impl<'a> Parser<'a> { } pos = peek_pos; - description = format!("expected `'}}'`, found `{maybe:?}`"); + description = format!("expected `'}}'`, found `{:?}`", maybe); } else { description = "expected `'}'` but string was terminated".to_owned(); // point at closing `"` @@ -690,12 +690,16 @@ impl<'a> Parser<'a> { // fill character if let Some(&(idx, c)) = self.cur.peek() { - if let Some((_, '>' | '<' | '^')) = self.cur.clone().nth(1) { - spec.fill = Some(c); - spec.fill_span = Some(self.span(idx, idx + 1)); - self.cur.next(); + match self.cur.clone().nth(1) { + Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => { + spec.fill = Some(c); + spec.fill_span = Some(self.span(idx, idx + 1)); + self.cur.next(); + } + _ => {} } } + // Alignment if self.consume('<') { spec.align = AlignLeft; @@ -908,7 +912,11 @@ impl<'a> Parser<'a> { ); } - found.then_some(cur) + if found { + Some(cur) + } else { + None + } } fn suggest_format(&mut self) { @@ -992,10 +1000,8 @@ fn find_width_map_from_snippet( // Alternatively, we could just count the trailing newlines and only trim one from the input if they don't match up. let input_no_nl = input.trim_end_matches('\n'); let unescaped = match unescape_string(snippet) { - Some(unescaped) => unescaped, - _ => { - return InputStringKind::NotALiteral; - } + Some(u) => u, + None => return InputStringKind::NotALiteral, }; let unescaped_no_nl = unescaped.trim_end_matches('\n'); @@ -1026,7 +1032,13 @@ fn find_width_map_from_snippet( width_mappings.push(InnerWidthMapping::new(pos, width, 0)); } - ('\\', Some((_, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => { + ('\\', Some((_, 'n'))) + | ('\\', Some((_, 't'))) + | ('\\', Some((_, 'r'))) + | ('\\', Some((_, '0'))) + | ('\\', Some((_, '\\'))) + | ('\\', Some((_, '\''))) + | ('\\', Some((_, '\"'))) => { width_mappings.push(InnerWidthMapping::new(pos, 2, 1)); let _ = s.next(); } @@ -1052,7 +1064,7 @@ fn find_width_map_from_snippet( .as_str() .get(..digits_len) .and_then(|digits| u32::from_str_radix(digits, 16).ok()) - .and_then(char::from_u32) + .and_then(std::char::from_u32) .map_or(1, char::len_utf8); // Skip the digits, for chars that encode to more than 1 utf-8 byte @@ -1108,7 +1120,11 @@ fn unescape_string(string: &str) -> Option<string::String> { let buf = string::String::from(string); let ok = true; - ok.then_some(buf) + if ok { + Some(buf) + } else { + None + } } // Assert a reasonable size for `Piece` |
