-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New Lint: pointer_as_const_underscore
#10587
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
Comments
Those are only the same if type inference doesn't pick a new type. e.g. let a = "a";
let a: *const u8 = a.as_ptr() as *const _; |
That could be written as in the case of changing mutability, something like The only place @rustbot claim |
oh snap, just noticed this is already covered by #10567 |
Just noticed that |
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 _
). Soas_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
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 _
).as_ptr()
here as an example, but the lint would include any function returning a pointer..as_ptr() as *const _
=.as_ptr()
, it isn't equal to justas *const _
.Lint Name
pointer_as_const_underscore
oras_ptr_as_const_underscore
Category
No response
Advantage
Cleaner code
Drawbacks
None that I can think of.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: