Add new condition to avoid derived code trigger lint

This commit is contained in:
Chris Wu 2024-01-19 15:01:33 +08:00 committed by GitHub
parent 7c389acd27
commit 9661f9b177
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then};
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::has_drop;
use clippy_utils::{get_parent_node, is_lint_allowed, peel_blocks};
use clippy_utils::{any_parent_is_automatically_derived, get_parent_node, is_lint_allowed, peel_blocks};
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{
@ -144,6 +144,7 @@ fn check_no_effect(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
}
} else if let StmtKind::Local(local) = stmt.kind {
if !is_lint_allowed(cx, NO_EFFECT_UNDERSCORE_BINDING, local.hir_id)
&& !any_parent_is_automatically_derived(cx.tcx, local.hir_id)
&& let Some(init) = local.init
&& local.els.is_none()
&& !local.pat.span.from_expansion()