Skip to content

Suggest box_string #7451

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

Closed
lengyijun opened this issue Jul 10, 2021 · 2 comments · Fixed by #7693
Closed

Suggest box_string #7451

lengyijun opened this issue Jul 10, 2021 · 2 comments · Fixed by #7693
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@lengyijun
Copy link
Contributor

lengyijun commented Jul 10, 2021

What it does

Check for usage for Box<String> in struct definition and function parameter.

Categories (optional)

Perf, Warn

What is the advantage of the recommended code over the original code

String already allocates on heap, Box<String> allocates a pointer on heap.
Similar lints: rc_buffer, box_vec, redundant_allocation,

Drawbacks

None.

Example

struct foo(Box<String>)
fn bar(a: Box<String>){}

Could be written as:

struct foo(String)
fn bar(a: String){}
@lengyijun lengyijun added the A-lint Area: New lints label Jul 10, 2021
@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label Jul 16, 2021
@F3real
Copy link
Contributor

F3real commented Jul 24, 2021

@rustbot claim

@camsteffen
Copy link
Contributor

camsteffen commented Jul 26, 2021

I think we should enhance and rename box_vec to box_collection. We can include all collection types like HashMap. String fits if you think about it as a Vec<u8>, which it actually is.

bors added a commit that referenced this issue Sep 22, 2021
Expand box_vec lint to box_collection

fixed #7451

changelog:
Report unnecessary boxing for collections
@bors bors closed this as completed in ef2e2f0 Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants