[significant_drop_tightening] Fix #11128

This commit is contained in:
Caio 2023-07-08 17:43:34 -03:00
parent c7bf05c1a4
commit 2be695bf29
5 changed files with 56 additions and 8 deletions

View file

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