Skip to content

Commit 849d902

Browse files
lint won't trigger for trait impls
1 parent eea92ca commit 849d902

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

clippy_lints/src/unused_underscore_prefixed_argument.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2+
use clippy_utils::is_trait_impl_item;
23
use clippy_utils::visitors::is_local_used;
34
use rustc_hir::def_id::LocalDefId;
45
use rustc_hir::intravisit::FnKind;
@@ -68,6 +69,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedUnderscorePrefixedArgument {
6869
if ctx.effective_visibilities.is_exported(def_id) {
6970
return;
7071
}
72+
let hir_id = ctx.tcx.local_def_id_to_hir_id(def_id);
73+
if is_trait_impl_item(ctx, hir_id) {
74+
return;
75+
}
7176
for param in body.params {
7277
if let PatKind::Binding(_, hir_id, name, _) = param.pat.kind
7378
&& name.as_str().starts_with('_')

tests/ui/unused_underscore_prefixed_argument.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ impl PrivStruct {
3232
// Will still raise lint because this is within a private struct
3333
}
3434

35+
pub trait Abc {
36+
fn abc(a: i32, _b: i32);
37+
}
38+
39+
pub struct Def;
40+
41+
impl Abc for Def {
42+
fn abc(a: i32, _b: i32) {}
43+
}
44+
3545
fn main() {}

0 commit comments

Comments
 (0)