3 #![warn(clippy::expect_fun_call)]
4 #![allow(clippy::to_string_in_format_args)]
6 /// Checks implementation of the `EXPECT_FUN_CALL` lint
22 fn expect(&self, msg: &str) {
27 let with_some = Some("value");
28 with_some.expect("error");
30 let with_none: Option<i32> = None;
31 with_none.expect("error");
33 let error_code = 123_i32;
34 let with_none_and_format: Option<i32> = None;
35 with_none_and_format.unwrap_or_else(|| panic!("Error {}: fake error", error_code));
37 let with_none_and_as_str: Option<i32> = None;
38 with_none_and_as_str.unwrap_or_else(|| panic!("Error {}: fake error", error_code));
40 let with_none_and_format_with_macro: Option<i32> = None;
41 with_none_and_format_with_macro.unwrap_or_else(|| panic!("Error {}: fake error", one!()));
43 let with_ok: Result<(), ()> = Ok(());
44 with_ok.expect("error");
46 let with_err: Result<(), ()> = Err(());
47 with_err.expect("error");
49 let error_code = 123_i32;
50 let with_err_and_format: Result<(), ()> = Err(());
51 with_err_and_format.unwrap_or_else(|_| panic!("Error {}: fake error", error_code));
53 let with_err_and_as_str: Result<(), ()> = Err(());
54 with_err_and_as_str.unwrap_or_else(|_| panic!("Error {}: fake error", error_code));
56 let with_dummy_type = Foo::new();
57 with_dummy_type.expect("another test string");
59 let with_dummy_type_and_format = Foo::new();
60 with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
62 let with_dummy_type_and_as_str = Foo::new();
63 with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
66 Some("foo").unwrap_or_else(|| panic!("{} {}", 1, 2));
68 //Issue #2979 - this should not lint
71 Some("foo").expect(msg);
75 fn get_string() -> String {
79 fn get_static_str() -> &'static str {
83 fn get_non_static_str(_: &u32) -> &str {
87 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
88 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
89 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
91 Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) });
92 Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) });
96 Some(true).unwrap_or_else(|| panic!("key {}, {}", 1, 2));
98 //Issue #4912 - the receiver is a &Option
102 opt_ref.unwrap_or_else(|| panic!("{:?}", opt_ref));