]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/expect_fun_call.rs
Ensure `expect_fun_call` bad suggestion is fixed
[rust.git] / tests / ui / expect_fun_call.rs
index 7f0ca0fe8095bbf0db7ef13ca92829012bac3e84..891ec883120c1f4a5a535629991ef2f9806e415b 100644 (file)
@@ -1,9 +1,10 @@
+// run-rustfix
+
 #![warn(clippy::expect_fun_call)]
-#![allow(clippy::useless_format)]
 
 /// Checks implementation of the `EXPECT_FUN_CALL` lint
 
-fn expect_fun_call() {
+fn main() {
     struct Foo;
 
     impl Foo {
@@ -51,14 +52,36 @@ fn expect(&self, msg: &str) {
     let with_dummy_type_and_as_str = Foo::new();
     with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
 
+    //Issue #2937
+    Some("foo").expect(format!("{} {}", 1, 2).as_ref());
+
     //Issue #2979 - this should not lint
-    let msg = "bar";
-    Some("foo").expect(msg);
+    {
+        let msg = "bar";
+        Some("foo").expect(msg);
+    }
 
-    Some("foo").expect({ &format!("error") });
-    Some("foo").expect(format!("error").as_ref());
+    {
+        fn get_string() -> String {
+            "foo".to_string()
+        }
 
-    Some("foo").expect(format!("{} {}", 1, 2).as_ref());
-}
+        fn get_static_str() -> &'static str {
+            "foo"
+        }
+
+        fn get_non_static_str(_: &u32) -> &str {
+            "foo"
+        }
+
+        Some("foo").expect(&get_string());
+        Some("foo").expect(get_string().as_ref());
+        Some("foo").expect(get_string().as_str());
 
-fn main() {}
+        Some("foo").expect(get_static_str());
+        Some("foo").expect(get_non_static_str(&0));
+    }
+
+    //Issue #3839
+    Some(true).expect(&format!("key {}, {}", 1, 2));
+}