Emit unnecessary_cast on raw pointers as well#10821
Conversation
|
r? @dswij (rustbot has picked a reviewer for you, use r? to override) |
I should always run cargo test before committing 😅
|
I think it would be useful to have tests for getting a pointer from somewhere else, example: let ptr: *const () = 1 as *const ();
let x = ptr as *const ();Does this lint handle generics properly? The following code should probably lint: fn owo<T>(ptr: *const T) {
let x = ptr as *const T;
}A test case casting to a different generic A test case involving a cast like EDIT: Huh, I just checked again, and
let _: *const u8 = [1u8, 2].as_ptr() as _;
let _: *mut u8 = [1u8, 2].as_mut_ptr() as _; |
I'm pretty sure this would function the same as any other cast but I added one anyway
Yes, since it checks |
|
Thanks for adding those tests! This all looks good to me. A tiny wording nitpick: I think that rustc uses "mutability" to refer to what you called "constness" (and "const" is normally things like |
|
The std library's docs of |
|
Oh look at that, it does. I guess in the context of raw pointers specifically, that wording is used instead? Weird. Then I have absolutely no issue with that in the name of consistency. |
dswij
left a comment
There was a problem hiding this comment.
Thanks for this! This LGTM, just a small comment on the suggestion message.
|
Thank you! @bors r+ |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Supersedes(?) #10782, since this and #10567 will cover the original issue.
Does not lint on type aliases or inferred types.
changelog: [
unnecessary_cast]: Also emit on casts between raw pointers with the same type and constness