Skip to content

Commit 989ce17

Browse files
committed
Auto merge of #12125 - cocodery:issue12045, r=xFrednet
Fix error warning span for issue12045 fixes [Issue#12045](#12045) In issue#12045, unexpected warning span occurs on attribute `#[derive(typed_builder::TypedBuilder)]`, actually the warning should underline `_lifetime`. In the source code we can find that the original intend is to warning on `ident.span`, but in this case, `stmt.span` is unequal with `ident.span`. So, fix the nit here is fine. Besides, `ident.span` have an accurate range than `stmt.span`. changelog: [`no_effect_underscore_binding`]: correct warning span
2 parents 6fd0258 + 73d7ce6 commit 989ce17

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

clippy_lints/src/no_effect.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then};
22
use clippy_utils::source::snippet_opt;
33
use clippy_utils::ty::has_drop;
4-
use clippy_utils::{get_parent_node, is_lint_allowed, peel_blocks};
4+
use clippy_utils::{any_parent_is_automatically_derived, get_parent_node, is_lint_allowed, peel_blocks};
55
use rustc_errors::Applicability;
66
use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::{
@@ -150,12 +150,13 @@ fn check_no_effect(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
150150
&& has_no_effect(cx, init)
151151
&& let PatKind::Binding(_, _, ident, _) = local.pat.kind
152152
&& ident.name.to_ident_string().starts_with('_')
153+
&& !any_parent_is_automatically_derived(cx.tcx, local.hir_id)
153154
{
154155
span_lint_hir(
155156
cx,
156157
NO_EFFECT_UNDERSCORE_BINDING,
157158
init.hir_id,
158-
stmt.span,
159+
ident.span,
159160
"binding to `_` prefixed variable with no side-effect",
160161
);
161162
return true;

tests/ui/no_effect.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -152,31 +152,31 @@ LL | FooString { s: s };
152152
| ^^^^^^^^^^^^^^^^^^^
153153

154154
error: binding to `_` prefixed variable with no side-effect
155-
--> $DIR/no_effect.rs:175:5
155+
--> $DIR/no_effect.rs:175:9
156156
|
157157
LL | let _unused = 1;
158-
| ^^^^^^^^^^^^^^^^
158+
| ^^^^^^^
159159
|
160160
= note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings`
161161
= help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]`
162162

163163
error: binding to `_` prefixed variable with no side-effect
164-
--> $DIR/no_effect.rs:178:5
164+
--> $DIR/no_effect.rs:178:9
165165
|
166166
LL | let _penguin = || println!("Some helpful closure");
167-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167+
| ^^^^^^^^
168168

169169
error: binding to `_` prefixed variable with no side-effect
170-
--> $DIR/no_effect.rs:180:5
170+
--> $DIR/no_effect.rs:180:9
171171
|
172172
LL | let _duck = Struct { field: 0 };
173-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173+
| ^^^^^
174174

175175
error: binding to `_` prefixed variable with no side-effect
176-
--> $DIR/no_effect.rs:182:5
176+
--> $DIR/no_effect.rs:182:9
177177
|
178178
LL | let _cat = [2, 4, 6, 8][2];
179-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
179+
| ^^^^
180180

181181
error: aborting due to 29 previous errors
182182

0 commit comments

Comments
 (0)