[significant_drop_tightening] Fix #11189

This commit is contained in:
Caio 2023-07-20 09:04:08 -03:00
parent fca1f9aec5
commit f0a16bb8a3
4 changed files with 64 additions and 12 deletions

View file

@ -331,13 +331,13 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
apa.last_method_span = span;
}
},
hir::StmtKind::Semi(expr) => {
if has_drop(expr, &apa.first_bind_ident, self.cx) {
hir::StmtKind::Semi(semi_expr) => {
if has_drop(semi_expr, &apa.first_bind_ident, self.cx) {
apa.has_expensive_expr_after_last_attr = false;
apa.last_stmt_span = DUMMY_SP;
return;
}
if let hir::ExprKind::MethodCall(_, _, _, span) = expr.kind {
if let hir::ExprKind::MethodCall(_, _, _, span) = semi_expr.kind {
apa.last_method_span = span;
}
},
@ -435,14 +435,26 @@ fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident, lcx: &LateContext<'_
&& let Res::Def(DefKind::Fn, did) = fun_path.res
&& lcx.tcx.is_diagnostic_item(sym::mem_drop, did)
&& let [first_arg, ..] = args
&& let hir::ExprKind::Path(hir::QPath::Resolved(_, arg_path)) = &first_arg.kind
&& let [first_arg_ps, .. ] = arg_path.segments
{
&first_arg_ps.ident == first_bind_ident
}
else {
false
let has_ident = |local_expr: &hir::Expr<'_>| {
if let hir::ExprKind::Path(hir::QPath::Resolved(_, arg_path)) = &local_expr.kind
&& let [first_arg_ps, .. ] = arg_path.segments
&& &first_arg_ps.ident == first_bind_ident
{
true
}
else {
false
}
};
if has_ident(first_arg) {
return true;
}
if let hir::ExprKind::Tup(value) = &first_arg.kind && value.iter().any(has_ident) {
return true;
}
}
false
}
fn is_inexpensive_expr(expr: &hir::Expr<'_>) -> bool {