Skip to content

Commit a4924e2

Browse files
committed
clean-up
1 parent 35f8bff commit a4924e2

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

clippy_lints/src/methods/err_expect.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::ERR_EXPECT;
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::msrvs::{self, Msrv};
4-
use clippy_utils::res::MaybeDef;
54
use clippy_utils::ty::has_debug_impl;
65
use rustc_errors::Applicability;
76
use rustc_lint::LateContext;
@@ -17,12 +16,10 @@ pub(super) fn check(
1716
err_span: Span,
1817
msrv: Msrv,
1918
) {
20-
if cx.typeck_results().expr_ty(recv).is_diag_item(cx, sym::Result)
21-
// Grabs the `Result<T, E>` type
22-
&& let result_type = cx.typeck_results().expr_ty(recv)
23-
// Tests if the T type in a `Result<T, E>` is not None
24-
&& let Some(data_type) = get_data_type(cx, result_type)
25-
// Tests if the T type in a `Result<T, E>` implements debug
19+
let result_ty = cx.typeck_results().expr_ty(recv);
20+
// Grabs the `Result<T, E>` type
21+
if let Some(data_type) = get_data_type(cx, result_ty)
22+
// Tests if the T type in a `Result<T, E>` implements Debug
2623
&& has_debug_impl(cx, data_type)
2724
&& msrv.meets(cx, msrvs::EXPECT_ERR)
2825
{
@@ -41,7 +38,7 @@ pub(super) fn check(
4138
/// Given a `Result<T, E>` type, return its data (`T`).
4239
fn get_data_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
4340
match ty.kind() {
44-
ty::Adt(_, args) if ty.is_diag_item(cx, sym::Result) => args.types().next(),
41+
ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => args.types().next(),
4542
_ => None,
4643
}
4744
}

clippy_lints/src/methods/ok_expect.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::res::MaybeDef;
32
use clippy_utils::ty::has_debug_impl;
43
use rustc_hir as hir;
54
use rustc_lint::LateContext;
@@ -10,10 +9,9 @@ use super::OK_EXPECT;
109

1110
/// lint use of `ok().expect()` for `Result`s
1211
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
13-
if cx.typeck_results().expr_ty(recv).is_diag_item(cx, sym::Result)
14-
// lint if the caller of `ok()` is a `Result`
15-
&& let result_type = cx.typeck_results().expr_ty(recv)
16-
&& let Some(error_type) = get_error_type(cx, result_type)
12+
let result_ty = cx.typeck_results().expr_ty(recv);
13+
// lint if the caller of `ok()` is a `Result`
14+
if let Some(error_type) = get_error_type(cx, result_ty)
1715
&& has_debug_impl(cx, error_type)
1816
{
1917
span_lint_and_help(
@@ -30,7 +28,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
3028
/// Given a `Result<T, E>` type, return its error type (`E`).
3129
fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
3230
match ty.kind() {
33-
ty::Adt(_, args) if ty.is_diag_item(cx, sym::Result) => args.types().nth(1),
31+
ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => args.types().nth(1),
3432
_ => None,
3533
}
3634
}

0 commit comments

Comments
 (0)