2023-07-27 06:40:22 -05:00
|
|
|
//@no-rustfix: overlapping suggestions
|
2021-03-01 15:31:04 -06:00
|
|
|
#![allow(unused_must_use)]
|
2023-09-26 06:40:10 -05:00
|
|
|
#![warn(clippy::write_literal)]
|
2021-03-01 15:31:04 -06:00
|
|
|
|
|
|
|
use std::io::Write;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut v = Vec::new();
|
|
|
|
|
2022-01-11 13:31:35 -06:00
|
|
|
writeln!(v, "{}", "{hello}");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
|
|
|
//~| NOTE: `-D clippy::write-literal` implied by `-D warnings`
|
2022-01-11 13:31:35 -06:00
|
|
|
writeln!(v, r"{}", r"{hello}");
|
2023-09-26 06:40:10 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-01-11 13:31:35 -06:00
|
|
|
writeln!(v, "{}", '\'');
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-01-11 13:31:35 -06:00
|
|
|
writeln!(v, "{}", '"');
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-08-30 07:20:49 -05:00
|
|
|
writeln!(v, r"{}", '"');
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-01-11 13:31:35 -06:00
|
|
|
writeln!(v, r"{}", '\'');
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2021-03-01 15:31:04 -06:00
|
|
|
writeln!(
|
2022-01-11 13:31:35 -06:00
|
|
|
v,
|
2021-03-01 15:31:04 -06:00
|
|
|
"some {}",
|
|
|
|
"hello \
|
2023-09-26 06:40:10 -05:00
|
|
|
world!",
|
|
|
|
//~^^ ERROR: literal with an empty format string
|
2021-03-01 15:31:04 -06:00
|
|
|
);
|
|
|
|
writeln!(
|
2022-01-11 13:31:35 -06:00
|
|
|
v,
|
2021-03-01 15:31:04 -06:00
|
|
|
"some {}\
|
|
|
|
{} \\ {}",
|
2023-09-28 03:12:00 -05:00
|
|
|
"1", "2", "3",
|
2021-03-01 15:31:04 -06:00
|
|
|
);
|
2022-08-30 07:20:49 -05:00
|
|
|
writeln!(v, "{}", "\\");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-08-30 07:20:49 -05:00
|
|
|
writeln!(v, r"{}", "\\");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-08-30 07:20:49 -05:00
|
|
|
writeln!(v, r#"{}"#, "\\");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-08-30 07:20:49 -05:00
|
|
|
writeln!(v, "{}", r"\");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-08-30 07:20:49 -05:00
|
|
|
writeln!(v, "{}", "\r");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2023-07-28 13:40:44 -05:00
|
|
|
// hard mode
|
|
|
|
writeln!(v, r#"{}{}"#, '#', '"');
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2023-07-28 13:40:44 -05:00
|
|
|
// should not lint
|
|
|
|
writeln!(v, r"{}", "\r");
|
2021-03-01 15:31:04 -06:00
|
|
|
}
|