2022-02-26 13:26:21 +00:00
|
|
|
#![allow(unused, clippy::print_literal, clippy::write_literal)]
|
|
|
|
#![warn(clippy::print_in_format_impl)]
|
|
|
|
use std::fmt::{Debug, Display, Error, Formatter};
|
2023-08-24 19:32:12 +00:00
|
|
|
//@no-rustfix
|
2022-02-26 13:26:21 +00:00
|
|
|
macro_rules! indirect {
|
|
|
|
() => {{ println!() }};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! nested {
|
|
|
|
($($tt:tt)*) => {
|
|
|
|
$($tt)*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Foo;
|
|
|
|
impl Debug for Foo {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
|
|
|
static WORKS_WITH_NESTED_ITEMS: bool = true;
|
|
|
|
|
|
|
|
print!("{}", 1);
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: use of `print!` in `Debug` impl
|
|
|
|
//~| NOTE: `-D clippy::print-in-format-impl` implied by `-D warnings`
|
2022-02-26 13:26:21 +00:00
|
|
|
println!("{}", 2);
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: use of `println!` in `Debug` impl
|
2022-02-26 13:26:21 +00:00
|
|
|
eprint!("{}", 3);
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: use of `eprint!` in `Debug` impl
|
2022-02-26 13:26:21 +00:00
|
|
|
eprintln!("{}", 4);
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: use of `eprintln!` in `Debug` impl
|
2022-02-26 13:26:21 +00:00
|
|
|
nested! {
|
|
|
|
println!("nested");
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: use of `println!` in `Debug` impl
|
2022-02-26 13:26:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
write!(f, "{}", 5);
|
|
|
|
writeln!(f, "{}", 6);
|
|
|
|
indirect!();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Foo {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
|
|
|
print!("Display");
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: use of `print!` in `Display` impl
|
2022-02-26 13:26:21 +00:00
|
|
|
write!(f, "Display");
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct UnnamedFormatter;
|
|
|
|
impl Debug for UnnamedFormatter {
|
|
|
|
fn fmt(&self, _: &mut Formatter) -> Result<(), Error> {
|
|
|
|
println!("UnnamedFormatter");
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: use of `println!` in `Debug` impl
|
2022-02-26 13:26:21 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
print!("outside fmt");
|
|
|
|
println!("outside fmt");
|
|
|
|
eprint!("outside fmt");
|
|
|
|
eprintln!("outside fmt");
|
|
|
|
}
|