1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![warn(clippy::expect_fun_call)]
11 #![allow(clippy::useless_format)]
13 /// Checks implementation of the `EXPECT_FUN_CALL` lint
15 fn expect_fun_call() {
19 fn new() -> Self { Foo }
21 fn expect(&self, msg: &str) {
26 let with_some = Some("value");
27 with_some.expect("error");
29 let with_none: Option<i32> = None;
30 with_none.expect("error");
32 let error_code = 123_i32;
33 let with_none_and_format: Option<i32> = None;
34 with_none_and_format.expect(&format!("Error {}: fake error", error_code));
36 let with_none_and_as_str: Option<i32> = None;
37 with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
39 let with_ok: Result<(), ()> = Ok(());
40 with_ok.expect("error");
42 let with_err: Result<(), ()> = Err(());
43 with_err.expect("error");
45 let error_code = 123_i32;
46 let with_err_and_format: Result<(), ()> = Err(());
47 with_err_and_format.expect(&format!("Error {}: fake error", error_code));
49 let with_err_and_as_str: Result<(), ()> = Err(());
50 with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
52 let with_dummy_type = Foo::new();
53 with_dummy_type.expect("another test string");
55 let with_dummy_type_and_format = Foo::new();
56 with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
58 let with_dummy_type_and_as_str = Foo::new();
59 with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
61 //Issue #2979 - this should not lint
63 Some("foo").expect(msg);
65 Some("foo").expect({ &format!("error") });
66 Some("foo").expect(format!("error").as_ref());