Skip to content

Request: A single lint for any usage at all of as #4771

@Lokathor

Description

@Lokathor

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.

Activity

Lokathor

Lokathor commented on Nov 5, 2019

@Lokathor
Author

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

RalfJung

RalfJung commented on Nov 5, 2019

@RalfJung
Member

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. :/

Lokathor

Lokathor commented on Nov 5, 2019

@Lokathor
Author

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

added
good first issueThese issues are a good way to get started with Clippy
A-lintArea: New lints
on Nov 6, 2019
basil-cow

basil-cow commented on Nov 16, 2019

@basil-cow
Contributor

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

Lokathor

Lokathor commented on Nov 16, 2019

@Lokathor
Author

pedantic for sure

flip1995

flip1995 commented on Nov 18, 2019

@flip1995
Member

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

added a commit that references this issue on Nov 28, 2019
d377486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @RalfJung@Lokathor@flip1995@basil-cow

      Issue actions

        Request: A single lint for any usage at all of `as` · Issue #4771 · rust-lang/rust-clippy