mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Implement the lint for expect
This commit is contained in:
parent
0b1bb5fbf3
commit
21b88ce290
@ -3658,10 +3658,15 @@ impl Methods {
|
||||
case_sensitive_file_extension_comparisons::check(cx, expr, span, recv, arg);
|
||||
}
|
||||
},
|
||||
("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),
|
||||
("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]) => {
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user