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

Warn for Vec<Box<T>> where T: Sized #3530

Closed
Kampfkarren opened this issue Dec 11, 2018 · 2 comments · Fixed by #3545
Closed

Warn for Vec<Box<T>> where T: Sized #3530

Kampfkarren opened this issue Dec 11, 2018 · 2 comments · Fixed by #3545
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group

Comments

@Kampfkarren
Copy link
Contributor

A fellow Rust programmer pointed me to this mistake in my code:

image

I'm quite new to Rust, but is there ever a point where Vec<Box<T: Sized>> is correct?

@sinkuu
Copy link
Contributor

sinkuu commented Dec 11, 2018

For example, it might make sense when T is a very large type. Calling .swap(0, 1) on Vec<T> will memcpy size_of::<T>() * 3, but it would be pointer_size * 3 for Vec<Box<T>>.

@flip1995 flip1995 added A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group good-first-issue These issues are a good way to get started with Clippy labels Dec 12, 2018
Kampfkarren added a commit to Kampfkarren/rust-clippy that referenced this issue Dec 13, 2018
bors added a commit that referenced this issue Dec 14, 2018
Adds lint for Vec<Box<T: Sized>>

This adds, and subsequently closes #3530. This is the first time I've ever worked with anything remotely close to internal Rust code, so I'm very much unsure about the if_chain! to figure this out!

I can't get rustfmt working on WSL with nightly 2018-12-07:

`error: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is unavailable for download`
bors added a commit that referenced this issue Dec 14, 2018
Adds lint for Vec<Box<T: Sized>>

This adds, and subsequently closes #3530. This is the first time I've ever worked with anything remotely close to internal Rust code, so I'm very much unsure about the if_chain! to figure this out!

I can't get rustfmt working on WSL with nightly 2018-12-07:

`error: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is unavailable for download`
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue May 5, 2020
Changes:

````
rustup rust-lang/rust#52994
Fix test
Line length fix
Remove references to sized for end users
Remove DUMMY_SP
Add suggestion for replacement
Update lint definitions
Lint for Vec<Box<T: Sized>> - Closes rust-lang#3530
Fix doc_markdown mixed case false positive
question_mark: Suggest Some(opt?) for if-else
redundant_field_names: Do not trigger on path with type params
question_mark: Lint only early returns
question_mark: Fix applicability
Remove obsolete comment
new_without_default, partialeq_ne_impl: Use span_lint_node
Update .stderr after rebase
cargo fmt and remove stabilized feature
Make suggestion Applicability::MachineApplicable
Address review feedback
Extract method
Check array lengths to prevent OOB access
Add suggestion for explicit_write lint
Fix write_with_newline escaping false positive
````
@benma
Copy link

benma commented Dec 26, 2020

Another example: reallocation of the vector when growing it is slower and copies more bytes when the size of T is large.

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 L-complexity Lint: Belongs in the complexity lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants