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() {
23 fn expect(&self, msg: &str) {
28 let with_some = Some("value");
29 with_some.expect("error");
31 let with_none: Option<i32> = None;
32 with_none.expect("error");
34 let error_code = 123_i32;
35 let with_none_and_format: Option<i32> = None;
36 with_none_and_format.expect(&format!("Error {}: fake error", error_code));
38 let with_none_and_as_str: Option<i32> = None;
39 with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
41 let with_ok: Result<(), ()> = Ok(());
42 with_ok.expect("error");
44 let with_err: Result<(), ()> = Err(());
45 with_err.expect("error");
47 let error_code = 123_i32;
48 let with_err_and_format: Result<(), ()> = Err(());
49 with_err_and_format.expect(&format!("Error {}: fake error", error_code));
51 let with_err_and_as_str: Result<(), ()> = Err(());
52 with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
54 let with_dummy_type = Foo::new();
55 with_dummy_type.expect("another test string");
57 let with_dummy_type_and_format = Foo::new();
58 with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
60 let with_dummy_type_and_as_str = Foo::new();
61 with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
63 //Issue #2979 - this should not lint
65 Some("foo").expect(msg);
67 Some("foo").expect({ &format!("error") });
68 Some("foo").expect(format!("error").as_ref());