-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve needless_pass_by_value #2117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Excluding a type whose reference also fulfills the trait bound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except for a style nit, this looks absolutely flawless to me
let preds = preds | ||
.iter() | ||
.filter_map(|pred| if let ty::Predicate::Trait(ref poly_trait_ref) = *pred { | ||
Some(poly_trait_ref.skip_binder()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the filter condition from below to here as an if
.filter(|p| !p.is_global()) | ||
.collect() | ||
}; | ||
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.to_vec()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there an intermediate vec?
Done. |
Thanks! |
While looking into #15569, I stumbled upon `clippy_utils::ptr`. This module was created in #2117, to share the logic from `ptr_arg` with `needless_pass_by_value`. But then later, #8409 removed the use of the logic from `ptr_arg`, which left `needless_pass_by_value` as the only user of this module. Still, I wanted to try to add docs to the module, but the two functions looked all too specific, so I thought it'd be better to just move them to `needless_pass_by_value`, in the hopes that whoever is looking at that lint will hopefully have enough context to understand what those functions are doing. changelog: none
serde::Serialize
which has a blanket implimpl Serialize for &S where S:Serialize
).ptr_arg
's logic forString
andVec
. Fixes needless_pass_by_value false positive with String #2114.&String
is suggested if.capacity()
is found.