|
1 | 1 | use clippy_utils::{ |
2 | 2 | diagnostics::span_lint_and_then, |
3 | | - expr_or_init, get_attr, path_to_local, |
| 3 | + expr_or_init, get_attr, match_def_path, path_to_local, paths, |
4 | 4 | source::{indent_of, snippet}, |
5 | 5 | }; |
6 | 6 | use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; |
7 | 7 | use rustc_errors::Applicability; |
8 | 8 | use rustc_hir::{ |
9 | 9 | self as hir, |
| 10 | + def::{DefKind, Res}, |
10 | 11 | intravisit::{walk_expr, Visitor}, |
11 | 12 | }; |
12 | 13 | use rustc_lint::{LateContext, LateLintPass, LintContext}; |
@@ -333,7 +334,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o |
333 | 334 | } |
334 | 335 | }, |
335 | 336 | hir::StmtKind::Semi(expr) => { |
336 | | - if has_drop(expr, &apa.first_bind_ident) { |
| 337 | + if has_drop(expr, &apa.first_bind_ident, self.cx) { |
337 | 338 | apa.has_expensive_expr_after_last_attr = false; |
338 | 339 | apa.last_stmt_span = DUMMY_SP; |
339 | 340 | return; |
@@ -430,11 +431,11 @@ fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> { |
430 | 431 | } |
431 | 432 | } |
432 | 433 |
|
433 | | -fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident) -> bool { |
| 434 | +fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident, lcx: &LateContext<'_>) -> bool { |
434 | 435 | if let hir::ExprKind::Call(fun, args) = expr.kind |
435 | 436 | && let hir::ExprKind::Path(hir::QPath::Resolved(_, fun_path)) = &fun.kind |
436 | | - && let [fun_ident, ..] = fun_path.segments |
437 | | - && fun_ident.ident.name == rustc_span::sym::drop |
| 437 | + && let Res::Def(DefKind::Fn, did) = fun_path.res |
| 438 | + && match_def_path(lcx, did, &paths::DROP) |
438 | 439 | && let [first_arg, ..] = args |
439 | 440 | && let hir::ExprKind::Path(hir::QPath::Resolved(_, arg_path)) = &first_arg.kind |
440 | 441 | && let [first_arg_ps, .. ] = arg_path.segments |
|
0 commit comments