3 #![warn(clippy::expect_fun_call)]
5 /// Checks implementation of the `EXPECT_FUN_CALL` lint
15 fn expect(&self, msg: &str) {
20 let with_some = Some("value");
21 with_some.expect("error");
23 let with_none: Option<i32> = None;
24 with_none.expect("error");
26 let error_code = 123_i32;
27 let with_none_and_format: Option<i32> = None;
28 with_none_and_format.unwrap_or_else(|| panic!("Error {}: fake error", error_code));
30 let with_none_and_as_str: Option<i32> = None;
31 with_none_and_as_str.unwrap_or_else(|| panic!("Error {}: fake error", error_code));
33 let with_ok: Result<(), ()> = Ok(());
34 with_ok.expect("error");
36 let with_err: Result<(), ()> = Err(());
37 with_err.expect("error");
39 let error_code = 123_i32;
40 let with_err_and_format: Result<(), ()> = Err(());
41 with_err_and_format.unwrap_or_else(|_| panic!("Error {}: fake error", error_code));
43 let with_err_and_as_str: Result<(), ()> = Err(());
44 with_err_and_as_str.unwrap_or_else(|_| panic!("Error {}: fake error", error_code));
46 let with_dummy_type = Foo::new();
47 with_dummy_type.expect("another test string");
49 let with_dummy_type_and_format = Foo::new();
50 with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
52 let with_dummy_type_and_as_str = Foo::new();
53 with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
56 Some("foo").unwrap_or_else(|| panic!("{} {}", 1, 2));
58 //Issue #2979 - this should not lint
61 Some("foo").expect(msg);
65 fn get_string() -> String {
69 fn get_static_str() -> &'static str {
73 fn get_non_static_str(_: &u32) -> &str {
77 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
78 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
79 Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
81 Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) });
82 Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) });
86 Some(true).unwrap_or_else(|| panic!("key {}, {}", 1, 2));
88 //Issue #4912 - the receiver is a &Option
92 opt_ref.unwrap_or_else(|| panic!("{:?}", opt_ref));