3

[`useless_vec`]: lint `vec!` invocations when a slice or an array would do by y2...

 11 months ago
source link: https://github.com/rust-lang/rust-clippy/pull/10901
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Conversation

Contributor

First off, sorry for that large diff in tests. A lot of tests seem to trigger the lint with this new change, so I decided to #![allow()] the lint in the affected tests to make reviewing this easier, and also split the commits up so that the first commit is the actual logic of the lint and the second commit contains all the test changes. The stuff that changed in the tests is mostly just line numbers now. So, as large as the diff looks, it's not actually that bad. sweat_smile
I manually went through all of these to find out about edge cases and decided to put them in tests/ui/vec.rs.

For more context, I wrote about the idea of this PR here: #2262 (comment) (that explains the logic)

Basically, it now also considers the case where a Vec is put in a local variable and the user only ever does things with it that one could also do with a slice or an array. This should catch a lot more cases, and (at least from looking at the tests) it does.

changelog: [useless_vec]: lint vec! invocations when a slice or an array would do (also considering local variables now)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK