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