rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Add `manual_as_slice` lint

Open nils-degroot opened this issue 6 months ago • 7 comments

This pr adds the manual_as_slice lint.

closes: rust-lang/rust-clippy#7633


changelog: add [manual_as_slice] lint

nils-degroot avatar May 15 '25 10:05 nils-degroot

I like manual_as_slice, it shows the intended behavior for the lint. I'll make the changes

nils-degroot avatar May 16 '25 12:05 nils-degroot

I think you need to re-bless the tests.

llogiq avatar May 16 '25 14:05 llogiq

I'm gonna restrict is to Vec, array and slice in that case, since doing this on a string also would not work

nils-degroot avatar May 18 '25 07:05 nils-degroot

Is it possible to get this working on vec since its not a language item?

nils-degroot avatar May 18 '25 08:05 nils-degroot

Is it possible to get this working on vec since its not a language item?

Language items are items that the compiler needs when it transforms code. For example, it needs panic!() as a language item, as it will generate calls to it. alloc::vec::Vec is not in this category, as the compiler never needs to transform the code in a way that would build a vector.

However, Vec is a diagnostic item, which means that you can get methods from clippy_utils (look for "diagnostic" there) to identify whether something is a Vec or not. Most of the things Clippy needs to identify in the standard library are marked as diagnostic items, and we can mark new items if we need them, so that we can easily use them in lints.

samueltardieu avatar May 18 '25 10:05 samueltardieu

:umbrella: The latest upstream changes (possibly d7b27ecbf319446dd9563a433e9694fa3bcd0d8c) made this pull request unmergeable. Please resolve the merge conflicts.

rustbot avatar Jun 02 '25 12:06 rustbot

:umbrella: The latest upstream changes (possibly b379d54c22f9f6b9577075d7f89645ac2498c931) made this pull request unmergeable. Please resolve the merge conflicts.

rustbot avatar Jun 05 '25 19:06 rustbot

since doing this on a string also would not work

I think it would work, you'd just need to suggest as_str/as_str_mut instead. But this could be left as a future improvement

ada4a avatar Oct 11 '25 17:10 ada4a