2018-10-30 15:21:23 -05:00
|
|
|
#![warn(clippy::expect_fun_call)]
|
|
|
|
#![allow(clippy::useless_format)]
|
|
|
|
|
|
|
|
/// Checks implementation of the `EXPECT_FUN_CALL` lint
|
|
|
|
|
|
|
|
fn expect_fun_call() {
|
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl Foo {
|
2018-12-09 16:26:16 -06:00
|
|
|
fn new() -> Self {
|
|
|
|
Foo
|
|
|
|
}
|
2018-10-30 15:21:23 -05:00
|
|
|
|
|
|
|
fn expect(&self, msg: &str) {
|
|
|
|
panic!("{}", msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let with_some = Some("value");
|
|
|
|
with_some.expect("error");
|
|
|
|
|
|
|
|
let with_none: Option<i32> = None;
|
|
|
|
with_none.expect("error");
|
|
|
|
|
|
|
|
let error_code = 123_i32;
|
|
|
|
let with_none_and_format: Option<i32> = None;
|
|
|
|
with_none_and_format.expect(&format!("Error {}: fake error", error_code));
|
|
|
|
|
|
|
|
let with_none_and_as_str: Option<i32> = None;
|
|
|
|
with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
|
|
|
|
|
|
|
|
let with_ok: Result<(), ()> = Ok(());
|
|
|
|
with_ok.expect("error");
|
|
|
|
|
|
|
|
let with_err: Result<(), ()> = Err(());
|
|
|
|
with_err.expect("error");
|
|
|
|
|
|
|
|
let error_code = 123_i32;
|
|
|
|
let with_err_and_format: Result<(), ()> = Err(());
|
|
|
|
with_err_and_format.expect(&format!("Error {}: fake error", error_code));
|
|
|
|
|
|
|
|
let with_err_and_as_str: Result<(), ()> = Err(());
|
|
|
|
with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
|
|
|
|
|
|
|
|
let with_dummy_type = Foo::new();
|
|
|
|
with_dummy_type.expect("another test string");
|
|
|
|
|
|
|
|
let with_dummy_type_and_format = Foo::new();
|
|
|
|
with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
|
|
|
|
|
|
|
|
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 #2979 - this should not lint
|
|
|
|
let msg = "bar";
|
|
|
|
Some("foo").expect(msg);
|
|
|
|
|
|
|
|
Some("foo").expect({ &format!("error") });
|
|
|
|
Some("foo").expect(format!("error").as_ref());
|
2019-01-19 06:13:06 -06:00
|
|
|
|
|
|
|
Some("foo").expect(format!("{} {}", 1, 2).as_ref());
|
2018-10-30 15:21:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|