Closed
Description
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 a n: u16
.
If foo
is called as foo(n as _)
, and at some point, the function signature of foo
changes to fn 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 the style
category, and be disabled by default).
Example
fn foo(n: usize) {}
let n: u16 = 256;
foo(n as _);
Could be written as:
fn foo(n: usize) {}
let n: u16 = 256;
foo(n as u16);