-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
mutable_key_type false positive for raw pointers #6745
Comments
I'd be happy to have a go at fixing this - it'd be my first contribution, so if someone could mentor/point me in the right directions then that would be great 😁. |
@kneasle 👍 Looks to me like these lines are wrong, and your task would be to figure out what the code should look like instead: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/mut_key.rs#L118-L120 |
Welcome to the project @kneasle, @Enselic has already linked the correct file and most likely location of the fix (Thank you for this). For bug fixes like these, it's usual helpful to check why they happen (In this case due to the use of a In this case, we want to allow If you like to work on this, please claim it with |
Both of you might also find it worthwhile to take a look at the implementation of |
You're right, that's an excellent hint! 👍 |
Thanks!
Also btw this false positive still happens for
Righto does this need to be a separate message or can I just do @rustbot claim in a message (I guess not but let's test it anyway...) |
@rustbot claim |
Good to know, then you can try fixing it for both cases 🙃
It doesn't have to be in its own comment, but the bot seems to be down right now 😅. In that case, I'll assign you |
Thanks 😄 |
Just to save you from some confusion later, I would like to point out that this is not quite accurate. The false positive will only trigger for
|
Oooh! So does that mean that the pattern which matches raw pointers is just wrong? And by extension, removing it will fix the bug? I'll probably replace it with a cheeky comment linking to this issue and the impl of |
Not quite, it can make sense if you actually want to compare them. The question is really what you want to have hashed and also why. 🙃 This lint however shouldn't care about it and only check if we have a type that is mutable in a way that could change the hash. For // vvvv Okay as only this get's hashed
let s: HashSet<*mut ()> = HashSet::new(); struct Penguin {
inner: *mut Inner
}
// Not okay as the implementation of hash for Penguin
// could depend on inner which can be mutated
// vvvvvvv
let s: HashSet<Penguin> = HashSet::new(); |
Ooooh - good point! So only the top-level |
Lint name: mutable_key_type
I tried this code:
I expected to see this happen: lint not triggered because raw pointers are compared and hashed by pointer value rather than by pointed-to value
Instead, this happened: lint triggered
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=601da4e6cf6eb0b2c178c32fcab35390
Meta
cargo clippy -V
: clippy 0.1.52 (d1206f9 2021-02-15)rustc -Vv
:The text was updated successfully, but these errors were encountered: