Skip to content

Commit 6fb736b

Browse files
committed
Fix false positive in needless_pass_by_value trait methods
1 parent 00081be commit 6fb736b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
8787

8888
// Exclude non-inherent impls
8989
if let Some(NodeItem(item)) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(node_id)) {
90-
if matches!(item.node, ItemImpl(_, _, _, _, Some(_), _, _) | ItemAutoImpl(..)) {
90+
if matches!(item.node, ItemImpl(_, _, _, _, Some(_), _, _) | ItemAutoImpl(..) |
91+
ItemTrait(..))
92+
{
9193
return;
9294
}
9395
}

tests/ui/needless_pass_by_value.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,11 @@ impl<T: Serialize, U> S<T, U> {
103103
}
104104
}
105105

106+
trait FalsePositive {
107+
fn visit_str(s: &str);
108+
fn visit_string(s: String) {
109+
Self::visit_str(&s);
110+
}
111+
}
112+
106113
fn main() {}

0 commit comments

Comments
 (0)