Skip to content

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

Merged
merged 4 commits into from
Oct 8, 2017

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
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