Implement the lint for expect

This commit is contained in:
Pavan Kumar Sunkara 2023-02-16 13:44:11 +00:00
parent 0b1bb5fbf3
commit 21b88ce290
2 changed files with 18 additions and 5 deletions

View File

@ -3658,10 +3658,15 @@ impl Methods {
case_sensitive_file_extension_comparisons::check(cx, expr, span, recv, arg);
}
},
("expect", [_]) => match method_call(recv) {
("expect", [_]) => {
match method_call(recv) {
Some(("ok", recv, [], _, _)) => ok_expect::check(cx, expr, recv),
Some(("err", recv, [], err_span, _)) => err_expect::check(cx, expr, recv, span, err_span, &self.msrv),
_ => expect_used::check(cx, expr, recv, false, self.allow_expect_in_tests),
}
if let ExprKind::Call(recv, _) = recv.kind {
unnecessary_literal_unwrap::check(cx, expr, recv, name);
}
},
("expect_err", [_]) => expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests),
("extend", [arg]) => {

View File

@ -7,5 +7,13 @@ LL | let val = Some(1).unwrap();
= help:
= note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
error: aborting due to previous error
error: used `expect()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:5:15
|
LL | let val = Some(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help:
error: aborting due to 2 previous errors