]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/expect_fun_call.fixed
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / expect_fun_call.fixed
index 1f74f6b8cf14be08ef0b6c2887a8191478552586..15172ae345c2e130161a811e1aca932376f6f899 100644 (file)
@@ -1,9 +1,15 @@
 // run-rustfix
-
 #![warn(clippy::expect_fun_call)]
+#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
 
 /// Checks implementation of the `EXPECT_FUN_CALL` lint
 
+macro_rules! one {
+    () => {
+        1
+    };
+}
+
 fn main() {
     struct Foo;
 
@@ -30,6 +36,9 @@ fn main() {
     let with_none_and_as_str: Option<i32> = None;
     with_none_and_as_str.unwrap_or_else(|| panic!("Error {}: fake error", error_code));
 
+    let with_none_and_format_with_macro: Option<i32> = None;
+    with_none_and_format_with_macro.unwrap_or_else(|| panic!("Error {}: fake error", one!()));
+
     let with_ok: Result<(), ()> = Ok(());
     with_ok.expect("error");
 
@@ -74,11 +83,27 @@ fn main() {
             "foo"
         }
 
-        Some("foo").unwrap_or_else(|| { panic!(get_string()) });
-        Some("foo").unwrap_or_else(|| { panic!(get_string()) });
-        Some("foo").unwrap_or_else(|| { panic!(get_string()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
+
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) });
+        Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) });
+    }
+
+    //Issue #3839
+    Some(true).unwrap_or_else(|| panic!("key {}, {}", 1, 2));
 
-        Some("foo").unwrap_or_else(|| { panic!(get_static_str()) });
-        Some("foo").unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) });
+    //Issue #4912 - the receiver is a &Option
+    {
+        let opt = Some(1);
+        let opt_ref = &opt;
+        opt_ref.unwrap_or_else(|| panic!("{:?}", opt_ref));
     }
+
+    let format_capture: Option<i32> = None;
+    format_capture.unwrap_or_else(|| panic!("{error_code}"));
+
+    let format_capture_and_value: Option<i32> = None;
+    format_capture_and_value.unwrap_or_else(|| panic!("{error_code}, {}", 1));
 }