-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lint for as _
casts
#8847
Comments
Thank you for the ticket, I would put this lint in the The implementation can be based on @rustbot label +good-first-issue |
It's not just |
@mikerite I generally agree with you that For one reason or another, I doubt I'd be able to remove all |
@rustbot claim |
Thanks @DevAccentor 🎉 |
What it does
(Discussed in #8846)
A lint to warn against
as _
conversions.Lint Name
as_underscore
Category
style
Advantage
as _
is the Rust equivalent of C/C++'s implicit casting (albeit with a visual signal that some cast is indeed happening), and comes with many of the same problems.e.g: consider a
fn foo(n: usize)
and an: u16
.If
foo
is called asfoo(n as _)
, and at some point, the function signature offoo
changes tofn foo(n: u8)
, then the code would continue to compile just fine, albeit with a (likely unexpected) integer truncation.Drawbacks
as _
is far more concise when the type being cast to is very wordy (but hence why this lint would live in thestyle
category, and be disabled by default).Example
Could be written as:
The text was updated successfully, but these errors were encountered: