Skip to content

Commit 755aa8d

Browse files
committed
Dogfood
1 parent 6071ecb commit 755aa8d

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

clippy_lints/src/significant_drop_tightening.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
7474
_: hir::def_id::LocalDefId,
7575
) {
7676
self.apas.clear();
77-
let initial_dummy_stmt = dummy_stmt_expr(&body.value);
77+
let initial_dummy_stmt = dummy_stmt_expr(body.value);
7878
let mut ap = AuxParams::new(&mut self.apas, &initial_dummy_stmt);
7979
StmtsChecker::new(&mut ap, cx, &mut self.seen_types, &mut self.type_cache).visit_body(body);
8080
for apa in ap.apas.values() {
@@ -93,13 +93,13 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
9393
let indent = " ".repeat(indent_of(cx, apa.last_stmt_span).unwrap_or(0));
9494
let init_method = snippet(cx, apa.first_method_span, "..");
9595
let usage_method = snippet(cx, apa.last_method_span, "..");
96-
let stmt = if apa.last_bind_ident != Ident::empty() {
96+
let stmt = if apa.last_bind_ident == Ident::empty() {
97+
format!("\n{indent}{init_method}.{usage_method};")
98+
} else {
9799
format!(
98100
"\n{indent}let {} = {init_method}.{usage_method};",
99101
snippet(cx, apa.last_bind_ident.span, ".."),
100102
)
101-
} else {
102-
format!("\n{indent}{init_method}.{usage_method};")
103103
};
104104
diag.span_suggestion_verbose(
105105
apa.first_stmt_span,
@@ -300,20 +300,22 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
300300
}
301301
}
302302
{
303-
let mut apa = AuxParamsAttr::default();
304-
apa.first_bind_ident = ident;
305-
apa.first_block_hir_id = self.ap.curr_block_hir_id;
306-
apa.first_block_span = self.ap.curr_block_span;
307-
apa.first_method_span = {
308-
let expr_or_init = expr_or_init(self.cx, expr);
309-
if let hir::ExprKind::MethodCall(_, local_expr, _, span) = expr_or_init.kind {
310-
local_expr.span.to(span)
311-
}
312-
else {
313-
expr_or_init.span
314-
}
303+
let mut apa = AuxParamsAttr {
304+
first_bind_ident: ident,
305+
first_block_hir_id: self.ap.curr_block_hir_id,
306+
first_block_span: self.ap.curr_block_span,
307+
first_method_span: {
308+
let expr_or_init = expr_or_init(self.cx, expr);
309+
if let hir::ExprKind::MethodCall(_, local_expr, _, span) = expr_or_init.kind {
310+
local_expr.span.to(span)
311+
}
312+
else {
313+
expr_or_init.span
314+
}
315+
},
316+
first_stmt_span: self.ap.curr_stmt.span,
317+
..Default::default()
315318
};
316-
apa.first_stmt_span = self.ap.curr_stmt.span;
317319
modify_apa_params(&mut apa);
318320
let _ = self.ap.apas.insert(hir_id, apa);
319321
} else {
@@ -445,9 +447,5 @@ fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident) -> bool {
445447
}
446448

447449
fn is_expensive_expr(expr: &hir::Expr<'_>) -> bool {
448-
if let hir::ExprKind::Path(_) = expr.kind {
449-
false
450-
} else {
451-
true
452-
}
450+
!matches!(expr.kind, hir::ExprKind::Path(_))
453451
}

0 commit comments

Comments
 (0)