You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
Activity
Lokathor commentedon Nov 5, 2019
Particularly, pointer casts that change from *const T to *mut T or *mut U are almost always wrong.
RalfJung commentedon Nov 5, 2019
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 betweenusize
/isize
and other integer types. :/Lokathor commentedon Nov 5, 2019
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
_.as_ptr() as *mut _
is Undefined Behavior #4774as_conversions
lint #4821basil-cow commentedon Nov 16, 2019
This lint seems a bit too aggressive for most codebases, does it belong in nursery or in pedantic?
Lokathor commentedon Nov 16, 2019
pedantic for sure
flip1995 commentedon Nov 18, 2019
I'd say it should be in restriction, since it restricts the language. (And is too pedantic even for
pedantic
)Auto merge of #4821 - Areredify:as_conversions, r=flip1995