Adding alignment to the list of cases to test for specific error message. Covers >
, ^
and <
.
This commit is contained in:
parent
e51e98dde6
commit
5b30586ba8
@ -289,10 +289,10 @@ impl<'a> Iterator for Parser<'a> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(&(_, maybe)) = self.cur.peek() {
|
if let Some(&(_, maybe)) = self.cur.peek() {
|
||||||
if maybe == '?' {
|
match maybe {
|
||||||
self.suggest_format();
|
'?' => self.suggest_format_debug(),
|
||||||
} else {
|
'<' | '^' | '>' => self.suggest_format_align(maybe),
|
||||||
self.suggest_positional_arg_instead_of_captured_arg(arg);
|
_ => self.suggest_positional_arg_instead_of_captured_arg(arg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -868,10 +868,9 @@ impl<'a> Parser<'a> {
|
|||||||
found.then_some(cur)
|
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(':')) {
|
if let (Some(pos), Some(_)) = (self.consume_pos('?'), self.consume_pos(':')) {
|
||||||
let word = self.word();
|
let word = self.word();
|
||||||
let _end = self.current_pos();
|
|
||||||
let pos = self.to_span_index(pos);
|
let pos = self.to_span_index(pos);
|
||||||
self.errors.insert(
|
self.errors.insert(
|
||||||
0,
|
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>) {
|
fn suggest_positional_arg_instead_of_captured_arg(&mut self, arg: Argument<'a>) {
|
||||||
if let Some(end) = self.consume_pos('.') {
|
if let Some(end) = self.consume_pos('.') {
|
||||||
let byte_pos = self.to_span_index(end);
|
let byte_pos = self.to_span_index(end);
|
||||||
|
@ -12,4 +12,10 @@ fn main() {
|
|||||||
//~^ ERROR invalid format string: expected `'}'`, found `'?'`
|
//~^ ERROR invalid format string: expected `'}'`, found `'?'`
|
||||||
format!("{?:#?}", bar);
|
format!("{?:#?}", bar);
|
||||||
//~^ ERROR invalid format string: expected format parameter to occur after `:`
|
//~^ ERROR invalid format string: expected format parameter to occur after `:`
|
||||||
|
format!("Hello {<5:}!", "x");
|
||||||
|
//~^ ERROR invalid format string: expected format parameter to occur after `:`
|
||||||
|
format!("Hello {^5:}!", "x");
|
||||||
|
//~^ ERROR invalid format string: expected format parameter to occur after `:`
|
||||||
|
format!("Hello {>5:}!", "x");
|
||||||
|
//~^ ERROR invalid format string: expected format parameter to occur after `:`
|
||||||
}
|
}
|
||||||
|
@ -50,5 +50,29 @@ LL | format!("{?:#?}", bar);
|
|||||||
|
|
|
|
||||||
= note: `?` comes after `:`, try `:?` instead
|
= note: `?` comes after `:`, try `:?` instead
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: invalid format string: expected format parameter to occur after `:`
|
||||||
|
--> $DIR/format-string-wrong-order.rs:15:21
|
||||||
|
|
|
||||||
|
LL | format!("Hello {<5:}!", "x");
|
||||||
|
| ^ expected `<` to occur after `:` in format string
|
||||||
|
|
|
||||||
|
= note: `<` comes after `:`.
|
||||||
|
|
||||||
|
error: invalid format string: expected format parameter to occur after `:`
|
||||||
|
--> $DIR/format-string-wrong-order.rs:17:21
|
||||||
|
|
|
||||||
|
LL | format!("Hello {^5:}!", "x");
|
||||||
|
| ^ expected `^` to occur after `:` in format string
|
||||||
|
|
|
||||||
|
= note: `^` comes after `:`.
|
||||||
|
|
||||||
|
error: invalid format string: expected format parameter to occur after `:`
|
||||||
|
--> $DIR/format-string-wrong-order.rs:19:21
|
||||||
|
|
|
||||||
|
LL | format!("Hello {>5:}!", "x");
|
||||||
|
| ^ expected `>` to occur after `:` in format string
|
||||||
|
|
|
||||||
|
= note: `>` comes after `:`.
|
||||||
|
|
||||||
|
error: aborting due to 9 previous errors
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user