-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Incorrect suggestion for ptr_eq warning leads to vtable_address_comparisons error #6524
Comments
Do what? Clippy didn't make a suggestion. The lint docs say:
Does this not apply to your example? |
Clippy’s suggestion for |
Okay, so there are two issues here. Correct me if I'm mistaken in any way since I am not very comfortable with pointers in Rust.
|
Right; I’ll open a separate issue for that when it becomes relevant.
The ideal behavior may be a little more context-dependent: we can suggest replacing ref-to-pointer casts with fn f(a: &u8, b: &u8) -> bool {
a as *const u8 == b as *const u8
// should suggest std::ptr::eq(a, b)
}
fn g(a: *const dyn Trait, b: *const dyn Trait) -> bool {
a as *const u8 == b as *const u8
// should not suggest std::ptr::eq(a, b)
} We probably need to exclude all pointer-to-pointer casts, since some of them currently lead to a suggestion that doesn’t even type-check: pub fn h(a: *const u16, b: *const u32) -> bool {
a as *const u8 == b as *const u8
// should not suggest str::ptr::eq(a, b)
} |
Great!
That should be possible. |
Due to a clippy warning about Arc::ptr_eq potentially comparing vtable meta data associated with wide pointers there was a recent change to explicitly only check the address pointers and discard any wide pointer meta data. The Rust libs team has since resolved to update Arc::ptr_eq so that it doesn't compare meta data for the wrapped value (such as a dyn trait vtable): rust-lang/rust#103763 In the meantime we can silence this clippy suggestion since the vtable is benign in this case anyway: rust-lang/rust-clippy#6524
Seeing that this hasn't received a reply since 2021, it looks like the intent of rust-lang/rust#80505 has now been merged as: rust-lang/rust#103763 Thus, this lint listed at https://rust-lang.github.io/rust-clippy/master/index.html#/vtable_address_comparisons is now stale/wrong (since Rust 1.72) for Also thanks @rib for back-linking to this issue, otherwise I probably wouldn't have found that it got fixed in 1.72 and ended up in a wild chase implementing target_ptr comparison by hand 😬 |
I think this issue can be closed now since |
Suppose we start with the following code:
Okay, let’s do that:
This suggestion is wrong. The cast to
*const u8
is important, and removing it has led back to the first error:Meta
cargo clippy -V
: clippy 0.0.212 (0b644e4 2020-12-26)rustc -Vv
:The text was updated successfully, but these errors were encountered: