Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,9 @@ impl<'input> Parser<'input> {
self.errors.insert(
0,
ParseError {
description: "expected format parameter to occur after `:`".to_owned(),
description:
"expected alignment specifier after `:` in format string; example: `{:>?}`"
.to_owned(),
note: None,
label: format!("expected `{}` to occur after `:`", alignment),
span: range,
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
//! sign := '+' | '-'
//! width := count
//! precision := count | '*'
//! type := '?' | 'x?' | 'X?' | identifier
//! type := '?' | 'x?' | 'X?' | 'o' | 'x' | 'X' | 'p' | 'b' | 'e' | 'E'
//! count := parameter | integer
//! parameter := argument '$'
//! ```
Expand Down
8 changes: 5 additions & 3 deletions tests/ui/fmt/format-string-wrong-order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ fn main() {
format!("{?:#?}", bar);
//~^ ERROR invalid format string: expected format parameter to occur after `:`
format!("Hello {<5:}!", "x");
//~^ ERROR invalid format string: expected format parameter to occur after `:`
//~^ ERROR invalid format string: expected alignment specifier after `:` in format string; example: `{:>?}`
format!("Hello {^5:}!", "x");
//~^ ERROR invalid format string: expected format parameter to occur after `:`
//~^ ERROR invalid format string: expected alignment specifier after `:` in format string; example: `{:>?}`
format!("Hello {>5:}!", "x");
//~^ ERROR invalid format string: expected format parameter to occur after `:`
//~^ ERROR invalid format string: expected alignment specifier after `:` in format string; example: `{:>?}`
println!("{0:#X>18}", 12345);
//~^ ERROR invalid format string: expected alignment specifier after `:` in format string; example: `{:>?}`
}
14 changes: 10 additions & 4 deletions tests/ui/fmt/format-string-wrong-order.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,29 @@ LL | format!("{?:#?}", bar);
|
= note: `?` comes after `:`, try `:?` instead

error: invalid format string: expected format parameter to occur after `:`
error: invalid format string: expected alignment specifier after `:` in format string; example: `{:>?}`
--> $DIR/format-string-wrong-order.rs:15:21
|
LL | format!("Hello {<5:}!", "x");
| ^ expected `<` to occur after `:` in format string

error: invalid format string: expected format parameter to occur after `:`
error: invalid format string: expected alignment specifier after `:` in format string; example: `{:>?}`
--> $DIR/format-string-wrong-order.rs:17:21
|
LL | format!("Hello {^5:}!", "x");
| ^ expected `^` to occur after `:` in format string

error: invalid format string: expected format parameter to occur after `:`
error: invalid format string: expected alignment specifier after `:` in format string; example: `{:>?}`
--> $DIR/format-string-wrong-order.rs:19:21
|
LL | format!("Hello {>5:}!", "x");
| ^ expected `>` to occur after `:` in format string

error: aborting due to 9 previous errors
error: invalid format string: expected alignment specifier after `:` in format string; example: `{:>?}`
--> $DIR/format-string-wrong-order.rs:21:20
|
LL | println!("{0:#X>18}", 12345);
| ^ expected `>` to occur after `:` in format string

error: aborting due to 10 previous errors

Loading