New lint: const_size_windows - #17440
Conversation
62e3e4a to
52555d6
Compare
This comment has been minimized.
This comment has been minimized.
52555d6 to
33160a2
Compare
|
No changes for 952ea88 |
33160a2 to
7b5b2f4
Compare
This comment has been minimized.
This comment has been minimized.
7b5b2f4 to
607b921
Compare
This comment has been minimized.
This comment has been minimized.
607b921 to
ba79030
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ba79030 to
4de20d3
Compare
This comment has been minimized.
This comment has been minimized.
4de20d3 to
e3098cd
Compare
This comment has been minimized.
This comment has been minimized.
e3098cd to
52aff85
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
This is currently linted
fn collect_windows(slice: &[u8]) {
let _: Vec<&[u8]> = slice.windows(2).collect();
}but this
fn collect_windows(slice: &[u8]) {
let _: Vec<&[u8]> = slice.array_windows::<2>().collect();
}is wrong. I also don't see any MSRV tests.
I replaced const-size usages of `slice::windows` with `slice::array_windows` in the codebase. However, I refrained from replacing usages in the input files for UI tests, instead allowing violations via #![allow(clippy::const_size_windows)].
52aff85 to
952ea88
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Thanks to @Gri-ffin for the well-spotted problem. I've concluded that the lint can't be [Examples of downstream consumers requiring slice]
Changes made:
[On why
|
|
☔ The latest upstream changes (possibly #17552) made this pull request unmergeable. Please resolve the merge conflicts. |
View all comments
See #6580
New lint
const_size_windows(style category). Checks forslice::windowswith constant window size that can be replaced withslice::array_windows, enabling array destructuring.Verifies that:
windowsmethod (sliceimpl).sizeis usable as generic const param.array_windowsstabilization [1]).Code suggestions:
MachineApplicableMaybeIncorrectcode withsource-equivalentcomparableslice::array_windowscall.array_windowshaving an impl on another trait for the receiver. Suggest UFCS in those cases.sizeis a complex const requiring surrounding braces.Also emits a "note":
slice::array_windowscall.size = 2destructures to[left, right],size = 3to[x, y, z]etc. No generic arg needed.Limitations of the lint:
slice::chunkswith const size. Thechunksmethod does not have a clean equivalent transformation sinceas_chunkshas a different return type [2].Open question: Should this be a
perflint or astylelint?windows_constandchunks_const#6580 suggests this as aperflint.slice::array_windowstoslice::windows.slice::array_windowsmention optimization [3]:changelog: new lint: [
const_size_windows].stderrfile): 29 positive test cases, 19 negative test casescargo testpasses locallycargo dev update_lintscargo dev fmt