ptr_cast_constness: check for implicit mut to const pointer coercion - #15747
ptr_cast_constness: check for implicit mut to const pointer coercion#15747zihan0822 wants to merge 1 commit into
ptr_cast_constness: check for implicit mut to const pointer coercion#15747Conversation
changelog: [`ptr_cast_constness`]: check for implicit mut to const pointer coercion Signed-off-by: Zihan <zihanli0822@gmail.com>
|
Lintcheck changes for cec69cd
This comment will be updated if you push new changes |
There was a problem hiding this comment.
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.
|
☔ The latest upstream changes (possibly #17369) made this pull request unmergeable. Please resolve the merge conflicts. |
Fixes #13667
changelog: [
ptr_cast_constness]: check for implicit mut to const pointer coercion