Closed
Description
What it does
As far as I know, every usage of .as_ptr() as *const _
is overcomplicated, as it has a pointer (.as_ptr()
) being casted to a pointer (as *const _
). So as_ptr() as *const _
would be equal to .as_ptr()
(Example of them being equal).
Even when they have the same result, ~19.1k files use this pattern.
Notes
- Similar to add new lint
as_underscore_ptr
to check foras *{const,mut} _
#10567, this could cause some issues (as one targetsas *const _
and the other one.as_ptr() as *const _
) - I used the common
.as_ptr()
here as an example, but the lint would include any function returning a pointer. - While
.as_ptr() as *const _
=.as_ptr()
, it isn't equal to justas *const _
.
Lint Name
pointer_as_const_underscore
or as_ptr_as_const_underscore
Category
No response
Advantage
Cleaner code
Drawbacks
None that I can think of.
Example
let a = "a";
let a_ptr = a.as_ptr() as *const _;
Could be written as:
let a = "a";
let a_ptr = a.as_ptr();