Skip to content

Commit 1fe6640

Browse files
committed
cleanup and clippy
1 parent 8ad8663 commit 1fe6640

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

clippy_lints/src/useless_pathbuf_conversion.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,32 @@ declare_lint_pass!(UselessPathbufConversion => [USELESS_PATHBUF_CONVERSION]);
3232
impl<'tcx> LateLintPass<'tcx> for UselessPathbufConversion {
3333
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
3434
// Only care about &PathBuf::from(...)
35-
if let ExprKind::AddrOf(_, _, inner) = &expr.kind {
36-
if let ExprKind::Call(func, args) = &inner.kind {
37-
if let ExprKind::Path(ref qpath) = func.kind {
38-
if let Some(def_id) = cx.qpath_res(qpath, func.hir_id).opt_def_id() {
39-
// check that the function is `from`
40-
if cx.tcx.item_name(def_id) != sym::from {
41-
return;
42-
}
35+
if let ExprKind::AddrOf(_, _, inner) = &expr.kind
36+
&& let ExprKind::Call(func, args) = &inner.kind
37+
&& let ExprKind::Path(ref qpath) = func.kind
38+
&& let Some(def_id) = cx.qpath_res(qpath, func.hir_id).opt_def_id()
39+
{
40+
// check that the function is `from`
41+
if cx.tcx.item_name(def_id) != sym::from {
42+
return;
43+
}
4344

44-
// get the type of the function's return value
45-
let ty = cx.typeck_results().expr_ty(inner);
45+
// get the type of the function's return value
46+
let ty = cx.typeck_results().expr_ty(inner);
4647

47-
if is_type_diagnostic_item(cx, ty, sym::PathBuf) {
48-
if let Some(arg) = args.get(0) {
49-
let sugg = format!("Path::new({})", snippet(cx, arg.span, ".."));
50-
span_lint_and_sugg(
51-
cx,
52-
USELESS_PATHBUF_CONVERSION,
53-
expr.span,
54-
"unnecessary `PathBuf::from` when a `&Path` is enough",
55-
"consider using",
56-
sugg,
57-
rustc_errors::Applicability::MachineApplicable,
58-
);
59-
}
60-
}
61-
}
62-
}
48+
if is_type_diagnostic_item(cx, ty, sym::PathBuf)
49+
&& let Some(arg) = args.first()
50+
{
51+
let sugg = format!("Path::new({})", snippet(cx, arg.span, ".."));
52+
span_lint_and_sugg(
53+
cx,
54+
USELESS_PATHBUF_CONVERSION,
55+
expr.span,
56+
"unnecessary `PathBuf::from` when a `&Path` is enough",
57+
"consider using",
58+
sugg,
59+
rustc_errors::Applicability::MachineApplicable,
60+
);
6361
}
6462
}
6563
}

0 commit comments

Comments
 (0)