Detect Python-style numeric grouping syntax in format strings (e.g. `{x:,}`)
and emit a clear diagnostic explaining that it is not supported in Rust.
This helps users coming from Python understand the error without exposing
the full set of valid Rust format specifiers.
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
91 lines
1.8 KiB
Rust
91 lines
1.8 KiB
Rust
// ignore-tidy-tab
|
|
|
|
fn main() {
|
|
format!("{
|
|
a");
|
|
//~^ ERROR invalid format string
|
|
format!("{ \
|
|
\
|
|
b");
|
|
//~^ ERROR invalid format string
|
|
format!(r#"{ \
|
|
|
|
rawc"#);
|
|
//~^^^ ERROR invalid format string
|
|
format!(r#"{ \n
|
|
\n
|
|
rawd"#);
|
|
//~^^^ ERROR invalid format string
|
|
format!("{ \n
|
|
\n
|
|
e");
|
|
//~^ ERROR invalid format string
|
|
format!("
|
|
{
|
|
a");
|
|
//~^ ERROR invalid format string
|
|
format!("
|
|
{
|
|
a
|
|
");
|
|
//~^^ ERROR invalid format string
|
|
format!(" \
|
|
{ \
|
|
\
|
|
b");
|
|
//~^ ERROR invalid format string
|
|
format!(" \
|
|
{ \
|
|
\
|
|
b \
|
|
\
|
|
");
|
|
//~^^^ ERROR invalid format string
|
|
format!(r#"
|
|
raw { \
|
|
\
|
|
c"#);
|
|
//~^^^ ERROR invalid format string
|
|
format!(r#"
|
|
raw { \n
|
|
\n
|
|
d"#);
|
|
//~^^^ ERROR invalid format string
|
|
format!("
|
|
{ \n
|
|
\n
|
|
e");
|
|
//~^ ERROR invalid format string
|
|
|
|
format!("
|
|
{asdf
|
|
}
|
|
", asdf=1);
|
|
// ok - this is supported
|
|
format!("
|
|
{
|
|
asdf}
|
|
", asdf=1);
|
|
//~^^ ERROR invalid format string
|
|
println!("\t{}");
|
|
//~^ ERROR 1 positional argument in format string
|
|
|
|
// note: `\x7B` is `{`
|
|
println!("\x7B}\u{8} {", 1);
|
|
//~^ ERROR invalid format string: expected `}` but string was terminated
|
|
|
|
println!("\x7B}\u8 {", 1);
|
|
//~^ ERROR incorrect unicode escape sequence
|
|
|
|
// note: raw strings don't escape `\xFF` and `\u{FF}` sequences
|
|
println!(r#"\x7B}\u{8} {"#, 1);
|
|
//~^ ERROR invalid format string: unmatched `}` found
|
|
|
|
println!(r#"\x7B}\u8 {"#, 1);
|
|
//~^ ERROR invalid format string: unmatched `}` found
|
|
|
|
println!("{x?}, world!",);
|
|
//~^ ERROR invalid format string: expected `}`, found `?`
|
|
println!("{x,}, world!",);
|
|
//~^ ERROR invalid format string: python's numeric grouping `,` is not supported in rust format strings
|
|
}
|