about summary refs log tree commit diff
path: root/tests/ui/format_args.fixed
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/format_args.fixed')
-rw-r--r--tests/ui/format_args.fixed105
1 files changed, 105 insertions, 0 deletions
diff --git a/tests/ui/format_args.fixed b/tests/ui/format_args.fixed
new file mode 100644
index 00000000000..8376566c4d6
--- /dev/null
+++ b/tests/ui/format_args.fixed
@@ -0,0 +1,105 @@
+// run-rustfix
+
+#![allow(unreachable_code)]
+#![allow(unused_macros)]
+#![allow(unused_variables)]
+#![allow(clippy::assertions_on_constants)]
+#![allow(clippy::eq_op)]
+#![warn(clippy::to_string_in_format_args)]
+
+use std::io::{stdout, Write};
+use std::ops::Deref;
+use std::panic::Location;
+
+struct Somewhere;
+
+impl ToString for Somewhere {
+    fn to_string(&self) -> String {
+        String::from("somewhere")
+    }
+}
+
+struct X(u32);
+
+impl Deref for X {
+    type Target = u32;
+
+    fn deref(&self) -> &u32 {
+        &self.0
+    }
+}
+
+struct Y<'a>(&'a X);
+
+impl<'a> Deref for Y<'a> {
+    type Target = &'a X;
+
+    fn deref(&self) -> &Self::Target {
+        &self.0
+    }
+}
+
+struct Z(u32);
+
+impl Deref for Z {
+    type Target = u32;
+
+    fn deref(&self) -> &u32 {
+        &self.0
+    }
+}
+
+impl std::fmt::Display for Z {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        write!(f, "Z")
+    }
+}
+
+macro_rules! my_macro {
+    () => {
+        // here be dragons, do not enter (or lint)
+        println!("error: something failed at {}", Location::caller().to_string());
+    };
+}
+
+macro_rules! my_other_macro {
+    () => {
+        Location::caller().to_string()
+    };
+}
+
+fn main() {
+    let x = &X(1);
+    let x_ref = &x;
+
+    let _ = format!("error: something failed at {}", Location::caller());
+    let _ = write!(
+        stdout(),
+        "error: something failed at {}",
+        Location::caller()
+    );
+    let _ = writeln!(
+        stdout(),
+        "error: something failed at {}",
+        Location::caller()
+    );
+    print!("error: something failed at {}", Location::caller());
+    println!("error: something failed at {}", Location::caller());
+    eprint!("error: something failed at {}", Location::caller());
+    eprintln!("error: something failed at {}", Location::caller());
+    let _ = format_args!("error: something failed at {}", Location::caller());
+    assert!(true, "error: something failed at {}", Location::caller());
+    assert_eq!(0, 0, "error: something failed at {}", Location::caller());
+    assert_ne!(0, 0, "error: something failed at {}", Location::caller());
+    panic!("error: something failed at {}", Location::caller());
+    println!("{}", *X(1));
+    println!("{}", ***Y(&X(1)));
+    println!("{}", Z(1));
+    println!("{}", **x);
+    println!("{}", ***x_ref);
+
+    println!("error: something failed at {}", Somewhere.to_string());
+    println!("{} and again {0}", x.to_string());
+    my_macro!();
+    println!("error: something failed at {}", my_other_macro!());
+}