Skip to content

Commit

Permalink
Fix linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ncMN committed Mar 29, 2022
1 parent be48609 commit bcc0c9a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3273,7 +3273,6 @@ Released 2018-09-13
[`exhaustive_enums`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_enums
[`exhaustive_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_structs
[`exit`]: https://rust-lang.github.io/rust-clippy/master/index.html#exit
[`expect_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_err
[`expect_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call
[`expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_used
[`expl_impl_clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy
Expand Down
15 changes: 9 additions & 6 deletions clippy_lints/src/methods/expect_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use rustc_lint::LateContext;
use rustc_span::sym;

pub(super) fn check(cx: &LateContext<'_>, expr: &rustc_hir::Expr<'_>, recv: &rustc_hir::Expr<'_>) {
if_chain! {
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);

then {
span_lint_and_help(cx, EXPECT_ERR, expr.span, "Called `.err().expect()` on a `Result` value", None, "`.expect_err()` can be called instead")
}
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result) {
span_lint_and_help(
cx,
EXPECT_ERR,
expr.span,
"called `.err().expect()` on a `Result` value",
None,
"`.expect_err()` can be called instead",
);
}
}
5 changes: 3 additions & 2 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ declare_clippy_lint! {
/// Because .expect_err() can be called directly.
///
/// ### Example
/// ```rust
/// ```should_panic
/// // example code where clippy issues a warning
/// let x: Result<u32, &str> = Ok(10);
/// x.err().expect("Testing err().expect()");
/// ```
/// Use instead:
/// ```rust
/// ```should_panic
/// // example code which does not raise clippy warning
/// let x: Result<u32, &str> = Ok(10);
/// x.expect_err("Testing expect_err");
Expand Down Expand Up @@ -2191,6 +2191,7 @@ impl_lint_pass!(Methods => [
NEEDLESS_SPLITN,
UNNECESSARY_TO_OWNED,
UNNECESSARY_JOIN,
EXPECT_ERR,
]);

/// Extracts a method call name, args, and `Span` of the method name.
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/expect_err.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Called `.err().expect()` on a `Result` value
error: called `.err().expect()` on a `Result` value
--> $DIR/expect_err.rs:3:5
|
LL | x.err().expect("Testing expect_err");
Expand Down

0 comments on commit bcc0c9a

Please sign in to comment.