Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Lokathor opened this issue Nov 4, 2019 · 6 comments · Fixed by #4821
Closed

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

Lokathor opened this issue Nov 4, 2019 · 6 comments · Fixed by #4821
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@Lokathor
Copy link

Lokathor commented Nov 4, 2019

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.

@Lokathor
Copy link
Author

Lokathor commented Nov 5, 2019

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

@RalfJung
Copy link
Member

RalfJung commented Nov 5, 2019

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
Copy link
Author

Lokathor commented 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

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints labels Nov 6, 2019
@basil-cow
Copy link
Contributor

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

@Lokathor
Copy link
Author

pedantic for sure

@flip1995
Copy link
Member

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

@bors bors closed this as completed in d377486 Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants