Skip to content

Conversation

zihan0822
Copy link
Contributor

@zihan0822 zihan0822 commented Sep 23, 2025

Fixes #13667

changelog: [ptr_cast_constness]: check for implicit mut to const pointer coercion

changelog: [`ptr_cast_constness`]: check for implicit mut to const
pointer coercion

Signed-off-by: Zihan <[email protected]>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 23, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 23, 2025

r? @y21

rustbot has assigned @y21.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Copy link

Lintcheck changes for cec69cd

Lint Added Removed Changed
clippy::ptr_cast_constness 18 0 1

This comment will be updated if you push new changes

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, if we start linting this pattern, it should be a new lint.

ptr_cast_constness is specifically about as casts. The motivation is that it's easy to unintentionally also change the pointee type alongside with constness with normal as casts, so like accidentally going from *mut i32 to *const i64.

This is not true for implicit coercions like what is proposed. That can only ever go from *mut T to *const T without changing the pointee and seems entirely harmless to me. Looking at the lintcheck results, I'm also not too convinced that it adds much value.

It should then likely also be a restriction lint given that there's IMO not really any advantage, just forces the user to be more explicit.
I'll also open a thread on zulip soon to gather some other opinions.

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest cast_const() for *mut to *const coercions (similar to ptr_cast_constness)
3 participants