2023-08-24 14:32:12 -05:00
|
|
|
//@no-rustfix: overlapping suggestions
|
2021-03-25 13:29:11 -05:00
|
|
|
#![allow(unused_must_use)]
|
2023-07-02 07:35:19 -05:00
|
|
|
#![warn(clippy::needless_raw_strings, clippy::write_literal)]
|
2021-03-25 13:29:11 -05:00
|
|
|
|
|
|
|
use std::io::Write;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut v = Vec::new();
|
|
|
|
|
2022-01-27 08:12:45 -06:00
|
|
|
writeln!(v, "{}", "{hello}");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
|
|
|
//~| NOTE: `-D clippy::write-literal` implied by `-D warnings`
|
2022-01-27 08:12:45 -06:00
|
|
|
writeln!(v, r"{}", r"{hello}");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: unnecessary raw string literal
|
|
|
|
//~| NOTE: `-D clippy::needless-raw-strings` implied by `-D warnings`
|
|
|
|
//~| ERROR: literal with an empty format string
|
2022-01-27 08:12:45 -06:00
|
|
|
writeln!(v, "{}", '\'');
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-01-27 08:12:45 -06:00
|
|
|
writeln!(v, "{}", '"');
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-09-21 12:02:37 -05:00
|
|
|
writeln!(v, r"{}", '"');
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-01-27 08:12:45 -06:00
|
|
|
writeln!(v, r"{}", '\'');
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2021-03-25 13:29:11 -05:00
|
|
|
writeln!(
|
2022-01-27 08:12:45 -06:00
|
|
|
v,
|
2021-03-25 13:29:11 -05:00
|
|
|
"some {}",
|
|
|
|
"hello \
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2021-03-25 13:29:11 -05:00
|
|
|
world!"
|
|
|
|
);
|
|
|
|
writeln!(
|
2022-01-27 08:12:45 -06:00
|
|
|
v,
|
2021-03-25 13:29:11 -05:00
|
|
|
"some {}\
|
|
|
|
{} \\ {}",
|
2023-08-24 14:32:12 -05:00
|
|
|
"1",
|
|
|
|
"2",
|
|
|
|
"3",
|
|
|
|
//~^ ERROR: literal with an empty format string
|
2021-03-25 13:29:11 -05:00
|
|
|
);
|
2022-09-21 12:02:37 -05:00
|
|
|
writeln!(v, "{}", "\\");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-09-21 12:02:37 -05:00
|
|
|
writeln!(v, r"{}", "\\");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-09-21 12:02:37 -05:00
|
|
|
writeln!(v, r#"{}"#, "\\");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-09-21 12:02:37 -05:00
|
|
|
writeln!(v, "{}", r"\");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
2022-09-21 12:02:37 -05:00
|
|
|
writeln!(v, "{}", "\r");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: literal with an empty format string
|
|
|
|
// hard mode
|
|
|
|
writeln!(v, r#"{}{}"#, '#', '"');
|
|
|
|
//~^ ERROR: literal with an empty format string
|
|
|
|
//~| ERROR: literal with an empty format string
|
|
|
|
// should not lint
|
|
|
|
writeln!(v, r"{}", "\r");
|
2021-03-25 13:29:11 -05:00
|
|
|
}
|