-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathio_other_error.rs
37 lines (36 loc) · 1.4 KB
/
io_other_error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::msrvs::{self, Msrv};
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, QPath};
use rustc_lint::LateContext;
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, path: &Expr<'_>, args: &[Expr<'_>], msrv: Msrv) {
if let [error_kind, error] = args
&& !expr.span.from_expansion()
&& !error_kind.span.from_expansion()
&& clippy_utils::is_expr_path_def_path(cx, path, &clippy_utils::paths::IO_ERROR_NEW)
&& clippy_utils::is_expr_path_def_path(
cx,
clippy_utils::expr_or_init(cx, error_kind),
&clippy_utils::paths::IO_ERRORKIND_OTHER,
)
&& let ExprKind::Path(QPath::TypeRelative(_, new_segment)) = path.kind
&& msrv.meets(cx, msrvs::IO_ERROR_OTHER)
{
span_lint_and_then(
cx,
super::IO_OTHER_ERROR,
expr.span,
"this can be `std::io::Error::other(_)`",
|diag| {
diag.multipart_suggestion_verbose(
"use `std::io::Error::other`",
vec![
(new_segment.ident.span, "other".to_owned()),
(error_kind.span.until(error.span.source_callsite()), String::new()),
],
Applicability::MachineApplicable,
);
},
);
}
}