suppress readonly_write_lock for underscore-prefixed bindings

This commit is contained in:
y21 2024-04-29 17:27:40 +02:00
parent c6bf9548d5
commit f0beaedf83
3 changed files with 14 additions and 1 deletions

View File

@ -4,7 +4,7 @@
use clippy_utils::source::snippet;
use clippy_utils::ty::is_type_diagnostic_item;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, Node};
use rustc_hir::{Expr, ExprKind, Node, PatKind};
use rustc_lint::LateContext;
use rustc_middle::mir::{Location, START_BLOCK};
use rustc_span::sym;
@ -25,6 +25,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, receiver
&& is_unwrap_call(cx, unwrap_call_expr)
&& let parent = cx.tcx.parent_hir_node(unwrap_call_expr.hir_id)
&& let Node::LetStmt(local) = parent
&& let PatKind::Binding(.., ident, _) = local.pat.kind
// if the binding is prefixed with `_`, it typically means
// that this guard only exists to protect a section of code
// rather than the contained data
&& !ident.as_str().starts_with('_')
&& let Some(mir) = enclosing_mir(cx.tcx, expr.hir_id)
&& let Some((local, _)) = mir
.local_decls

View File

@ -43,3 +43,7 @@ fn main() {
*writer1 = *writer2;
}
}
fn issue12733(rw: &RwLock<()>) {
let _write_guard = rw.write().unwrap();
}

View File

@ -43,3 +43,7 @@ fn main() {
*writer1 = *writer2;
}
}
fn issue12733(rw: &RwLock<()>) {
let _write_guard = rw.write().unwrap();
}