]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/format_args_unfixable.rs
Rollup merge of #99474 - aDotInTheVoid:rustdoc-json-noinline-test-cleanup, r=CraftSpider
[rust.git] / src / tools / clippy / tests / ui / format_args_unfixable.rs
1 #![allow(clippy::assertions_on_constants)]
2 #![allow(clippy::eq_op)]
3 #![warn(clippy::format_in_format_args)]
4 #![warn(clippy::to_string_in_format_args)]
5
6 use std::io::{stdout, Error, ErrorKind, Write};
7 use std::ops::Deref;
8 use std::panic::Location;
9
10 macro_rules! my_macro {
11     () => {
12         // here be dragons, do not enter (or lint)
13         println!("error: {}", format!("something failed at {}", Location::caller()));
14     };
15 }
16
17 macro_rules! my_other_macro {
18     () => {
19         format!("something failed at {}", Location::caller())
20     };
21 }
22
23 fn main() {
24     let error = Error::new(ErrorKind::Other, "bad thing");
25     let x = 'x';
26
27     println!("error: {}", format!("something failed at {}", Location::caller()));
28     println!("{}: {}", error, format!("something failed at {}", Location::caller()));
29     println!("{:?}: {}", error, format!("something failed at {}", Location::caller()));
30     println!("{{}}: {}", format!("something failed at {}", Location::caller()));
31     println!(r#"error: "{}""#, format!("something failed at {}", Location::caller()));
32     println!("error: {}", format!(r#"something failed at "{}""#, Location::caller()));
33     println!("error: {}", format!("something failed at {} {0}", Location::caller()));
34     let _ = format!("error: {}", format!("something failed at {}", Location::caller()));
35     let _ = write!(
36         stdout(),
37         "error: {}",
38         format!("something failed at {}", Location::caller())
39     );
40     let _ = writeln!(
41         stdout(),
42         "error: {}",
43         format!("something failed at {}", Location::caller())
44     );
45     print!("error: {}", format!("something failed at {}", Location::caller()));
46     eprint!("error: {}", format!("something failed at {}", Location::caller()));
47     eprintln!("error: {}", format!("something failed at {}", Location::caller()));
48     let _ = format_args!("error: {}", format!("something failed at {}", Location::caller()));
49     assert!(true, "error: {}", format!("something failed at {}", Location::caller()));
50     assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
51     assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
52     panic!("error: {}", format!("something failed at {}", Location::caller()));
53
54     // negative tests
55     println!("error: {}", format_args!("something failed at {}", Location::caller()));
56     println!("error: {:>70}", format!("something failed at {}", Location::caller()));
57     println!("error: {} {0}", format!("something failed at {}", Location::caller()));
58     println!("{} and again {0}", format!("hi {}", x));
59     my_macro!();
60     println!("error: {}", my_other_macro!());
61 }