diff options
| author | bors <bors@rust-lang.org> | 2024-08-25 17:28:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-25 17:28:51 +0000 |
| commit | 083e20a6dcf8369b104f7e2fa1c31596d82992ca (patch) | |
| tree | 9ef328c4bb618e0257e965e8ff792e2fc017b89a /clippy_lints/src | |
| parent | 40bca0d944c6356dfd3a65e2466f3a05ee2dbb83 (diff) | |
| parent | 197b444407b86b1990f4051b1cb28181e45eb965 (diff) | |
Auto merge of #13113 - nyurik:ignore-pass-by-val-for-pfx, r=blyxyas
Ignore underscore-prefixed args for needless_pass_by_value lint When a user explicitly tags a param as unused (yet?), there is no need to raise another lint on it. fixes #7295 Note that I had to rename all `_*` params in the tests, but kept the variable name length to avoid extra changes in the expected output. changelog: [`needless_pass_by_value`]: do not warn if the argument name starts with an `_`
Diffstat (limited to 'clippy_lints/src')
| -rw-r--r-- | clippy_lints/src/needless_pass_by_value.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index addb4b1aee8..5bf390056f6 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { }) .collect::<Vec<_>>(); - // Collect moved variables and spans which will need dereferencings from the + // Collect moved variables and spans which will need dereferencing from the // function body. let MovedVariablesCtxt { moved_vars } = { let mut ctx = MovedVariablesCtxt::default(); @@ -148,12 +148,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { return; } - // Ignore `self`s. - if idx == 0 { - if let PatKind::Binding(.., ident, _) = arg.pat.kind { - if ident.name == kw::SelfLower { - continue; - } + // Ignore `self`s and params whose variable name starts with an underscore + if let PatKind::Binding(.., ident, _) = arg.pat.kind { + if idx == 0 && ident.name == kw::SelfLower { + continue; + } + if ident.name.as_str().starts_with('_') { + continue; } } |
