clippy: fix ptr_as_ptr lint - #907
Conversation
b4844f2 to
ce70c24
Compare
|
I'm not super sure yet if I want to accept fixes for pedantic warnings (this one is quite larger after all). Is there a benefit to doing so? |
|
The benefit of this lint is that I also think |
| let ut = unsafe { &mut *ptr }; | ||
| ut.p_funcs = &FUNCS; | ||
| ut.context = tb as *const TextBuffer as *mut _; | ||
| ut.context = ptr::from_ref(tb).cast_mut().cast(); |
There was a problem hiding this comment.
"from_ref cast mut cast" is not as readable to me as "as text buffer as whatever", personally. It'd be great to hear the opinion of others but I doubt anyone just randomly shows up haha. (I mean people that aren't too opinionated on Rust-correctness, otherwise that'd be unfair.)
There was a problem hiding this comment.
Being explicit when casting mutability makes the intent clearer and, in my opinion, improves readability.
In the case of .cast_mut(), this looks like a potentially suspicious operation, so I looked into this instance further. It seems the context field may be incorrectly typed, as the corresponding C definition uses const void *, while the Rust definition uses *mut c_void:
Line 1266 in 3e20615
There was a problem hiding this comment.
Follow-up to #730.
https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr