]> git.lizzy.rs Git - rust.git/blob - tests/ui/print_in_format_impl.rs
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / print_in_format_impl.rs
1 #![allow(unused, clippy::print_literal, clippy::write_literal)]
2 #![warn(clippy::print_in_format_impl)]
3 use std::fmt::{Debug, Display, Error, Formatter};
4
5 macro_rules! indirect {
6     () => {{ println!() }};
7 }
8
9 macro_rules! nested {
10     ($($tt:tt)*) => {
11         $($tt)*
12     };
13 }
14
15 struct Foo;
16 impl Debug for Foo {
17     fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
18         static WORKS_WITH_NESTED_ITEMS: bool = true;
19
20         print!("{}", 1);
21         println!("{}", 2);
22         eprint!("{}", 3);
23         eprintln!("{}", 4);
24         nested! {
25             println!("nested");
26         };
27
28         write!(f, "{}", 5);
29         writeln!(f, "{}", 6);
30         indirect!();
31
32         Ok(())
33     }
34 }
35
36 impl Display for Foo {
37     fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
38         print!("Display");
39         write!(f, "Display");
40
41         Ok(())
42     }
43 }
44
45 struct UnnamedFormatter;
46 impl Debug for UnnamedFormatter {
47     fn fmt(&self, _: &mut Formatter) -> Result<(), Error> {
48         println!("UnnamedFormatter");
49         Ok(())
50     }
51 }
52
53 fn main() {
54     print!("outside fmt");
55     println!("outside fmt");
56     eprint!("outside fmt");
57     eprintln!("outside fmt");
58 }