Skip to content
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

idea: Combination of str_to_string and needless_closure #317

Open
llogiq opened this issue Sep 7, 2015 · 2 comments
Open

idea: Combination of str_to_string and needless_closure #317

llogiq opened this issue Sep 7, 2015 · 2 comments
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types

Comments

@llogiq
Copy link
Contributor

llogiq commented Sep 7, 2015

Currently, the str_to_string lint and the needless_closure lint miss the following: x.map(|s| s.to_string()) (where x is an iterator of &str). This can be replaced with x.map(str::to_owned), to both remove the closure and change the function.

@Manishearth Manishearth added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types A-lint Area: New lints labels Sep 7, 2015
@llogiq
Copy link
Contributor Author

llogiq commented Sep 8, 2015

It should be possible to special-case eta_reduction for this. Perhaps with a sort of whitelist of { input_ref: &[RefType], input_type: &[&'static str], method_name: &'static str, replacement: &'static str } or some such. Though I struggle to find more examples than the above and maybe x.map(|s| s.to_string())(where x is already a IntoIter<Item=&String>), which can be completely removed, or changed to clone.

@Manishearth
Copy link
Member

This actually doesn't always work, since autoderef is usually acting when running s.to_owned() over an iterator (it's probably an &String or something since iterators often end up adding more &ptrs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

2 participants