Skip to content

Conversation

sinkuu
Copy link
Contributor

@sinkuu sinkuu commented Oct 8, 2017

  • Reducing false positives by excluding a type whose reference also fullfils the trait bound (e.g. an argument bounded by serde::Serialize which has a blanket impl impl Serialize for &S where S:Serialize).
  • Use ptr_arg's logic for String and Vec. Fixes needless_pass_by_value false positive with String #2114.
    • Now &String is suggested if .capacity() is found.

Copy link
Contributor

@oli-obk oli-obk left a 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())
Copy link
Contributor

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())
Copy link
Contributor

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?

@sinkuu
Copy link
Contributor Author

sinkuu commented Oct 8, 2017

Done.

@oli-obk oli-obk merged commit 73a1dd8 into rust-lang:master Oct 8, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Oct 8, 2017

Thanks!

@sinkuu sinkuu deleted the improve_take_by_value branch October 8, 2017 23:27
github-merge-queue bot pushed a commit that referenced this pull request Sep 25, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants