Rust-clippy: Request: A single lint for any usage at all of `as`

Created on 4 Nov 2019  路  6Comments  路  Source: rust-lang/rust-clippy

Hello there's currently a few different lints related to the usage of the as keyword. I'd like a single lint (allow by default) that just triggers on any usage of as at all.

L-lint good-first-issue

Most helpful comment

I'd say it should be in restriction, since it _restricts_ the language. (And is too pedantic even for pedantic)

All 6 comments

Particularly, pointer casts that change from *const T to *mut T or *mut U are _almost always_ wrong.

Particularly, pointer casts that change from *const T to *mut T or *mut U are almost always wrong.

Some people told me they do these casts fairly freely as they just don't use mutability on raw poitners as meaning anything. In particular with NonNull only having a *mut API surface, that can easily happen.

I'd still welcome both (a) a specific lint for mutability-changing raw ptr casts, and also (b) a general lint against as. Though for the latter, there's currently no good alternative that I know of for casts between usize/isize and other integer types. :/

myself, for doing that i would turn on the lint and then make designated const functions that have allow attributes. then you have clear names for truncating, signed-ness flipping, and extending

This lint seems a bit too aggressive for most codebases, does it belong in nursery or in pedantic?

pedantic for sure

I'd say it should be in restriction, since it _restricts_ the language. (And is too pedantic even for pedantic)

Was this page helpful?
0 / 5 - 0 ratings