3 #![warn(clippy::expect_fun_call)]
4 #![allow(clippy::to_string_in_format_args)]
6 /// Checks implementation of the `EXPECT_FUN_CALL` lint
16 fn expect(&self, msg: &str) {
21 let with_some = Some("value");
22 with_some.expect("error");
24 let with_none: Option<i32> = None;
25 with_none.expect("error");
27 let error_code = 123_i32;
28 let with_none_and_format: Option<i32> = None;
29 with_none_and_format.unwrap_or_else(|| panic!("Error {}: fake error", error_code));
31 let with_none_and_as_str: Option<i32> = None;
32 with_none_and_as_str.unwrap_or_else(|| panic!("Error {}: fake error", error_code));
34 let with_ok: Result<(), ()> = Ok(());
35 with_ok.expect("error");
37 let with_err: Result<(), ()> = Err(());
38 with_err.expect("error");
40 let error_code = 123_i32;
41 let with_err_and_format: Result<(), ()> = Err(());
42 with_err_and_format.unwrap_or_else(|_| panic!("Error {}: fake error", error_code));
44 let with_err_and_as_str: Result<(), ()> = Err(());
45 with_err_and_as_str.unwrap_or_else(|_| panic!("Error {}: fake error", error_code));
47 let with_dummy_type = Foo::new();
48 with_dummy_type.expect("another test string");
50 let with_dummy_type_and_format = Foo::new();
51 with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
53 let with_dummy_type_and_as_str = Foo::new();
54 with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
57 Some("foo").unwrap_or_else(|| panic!("{} {}", 1, 2));
59 //Issue #2979 - this should not lint
62 Some("foo").expect(msg);
66 fn get_string() -> String {
70 fn get_static_str() -> &'static str {
74 fn get_non_static_str(_: &u32) -> &str {
78 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
79 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
80 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
82 Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) });
83 Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) });
87 Some(true).unwrap_or_else(|| panic!("key {}, {}", 1, 2));
89 //Issue #4912 - the receiver is a &Option
93 opt_ref.unwrap_or_else(|| panic!("{:?}", opt_ref));