diff options
| author | Mads Ravn <madsravn@gmail.com> | 2024-01-07 20:39:46 +0100 |
|---|---|---|
| committer | Mads Ravn <madsravn@gmail.com> | 2024-01-07 20:39:46 +0100 |
| commit | 5b30586ba8905a1a14d5d05522c697ab1b0800f7 (patch) | |
| tree | 0bab470ee20a17ca5e03588a4ef38730fdc1da5e /compiler/rustc_parse_format/src/lib.rs | |
| parent | e51e98dde6a60637b6a71b8105245b629ac3fe77 (diff) | |
| download | rust-5b30586ba8905a1a14d5d05522c697ab1b0800f7.tar.gz rust-5b30586ba8905a1a14d5d05522c697ab1b0800f7.zip | |
Adding alignment to the list of cases to test for specific error message. Covers `>`, `^` and `<`.
Diffstat (limited to 'compiler/rustc_parse_format/src/lib.rs')
| -rw-r--r-- | compiler/rustc_parse_format/src/lib.rs | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index e886db3da29..eff54ac9308 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -289,10 +289,10 @@ impl<'a> Iterator for Parser<'a> { } } else { if let Some(&(_, maybe)) = self.cur.peek() { - if maybe == '?' { - self.suggest_format(); - } else { - self.suggest_positional_arg_instead_of_captured_arg(arg); + match maybe { + '?' => self.suggest_format_debug(), + '<' | '^' | '>' => self.suggest_format_align(maybe), + _ => self.suggest_positional_arg_instead_of_captured_arg(arg), } } } @@ -868,10 +868,9 @@ impl<'a> Parser<'a> { found.then_some(cur) } - fn suggest_format(&mut self) { + fn suggest_format_debug(&mut self) { if let (Some(pos), Some(_)) = (self.consume_pos('?'), self.consume_pos(':')) { let word = self.word(); - let _end = self.current_pos(); let pos = self.to_span_index(pos); self.errors.insert( 0, @@ -887,6 +886,23 @@ impl<'a> Parser<'a> { } } + fn suggest_format_align(&mut self, alignment: char) { + if let Some(pos) = self.consume_pos(alignment) { + let pos = self.to_span_index(pos); + self.errors.insert( + 0, + ParseError { + description: "expected format parameter to occur after `:`".to_owned(), + note: Some(format!("`{}` comes after `:`.", alignment)), + label: format!("expected `{}` to occur after `:`", alignment).to_owned(), + span: pos.to(pos), + secondary_label: None, + suggestion: Suggestion::None, + }, + ); + } + } + fn suggest_positional_arg_instead_of_captured_arg(&mut self, arg: Argument<'a>) { if let Some(end) = self.consume_pos('.') { let byte_pos = self.to_span_index(end); |
