Skip to content

type-mismatch incorrectly emitted when a struct/emum with a field named state derives Hash #15043

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

Closed
LikeLakers2 opened this issue Jun 13, 2023 · 2 comments
Labels
C-bug Category: bug

Comments

@LikeLakers2
Copy link

rust-analyzer version:
rust-analyzer version: 0.3.1549-standalone (d567091 2023-06-11)

rustc version:
rustc 1.70.0 (90c541806 2023-05-31)

relevant settings:
None that I can think of (though I would be happy to share the settings I've set, if need be!)


Hi there! I was writing up some code for a custom collection type, when rust-analyzer started emitting a type-mismatch error on me. I found this odd, because rust was itself was still compiling the code just fine - cargo check, cargo build, and cargo clippy all ran without error, even after saving the file with the supposed type-mismatch error.

Upon further investigation, I've found that I'm able to reliably reproduce the issue when all of the following are true:

  1. A struct or enum variant has a field named state
  2. The struct or enum with that field has a #[derive(Hash)] attribute.

Upon meeting these conditions, rust-analyzer will start incorrectly emitting a type-mismatch error until either 1) the Hash derive is removed, or 2) the state field is renamed. (To be clear, I am unsure if this issue is specific to the Hash derive. It's possible it may affect other derives as well.)

Here is a minimal reproduction of the issue - both a struct and enum are provided.

#[derive(Hash)]
pub struct RaBugStruct {
	state: ()
}

#[derive(Hash)]
pub enum RaBugEnum {
	St {
		state: ()
	}
}

Either of those will produce a type-mismatch error from rust-analyzer, that says expected &mut {unknown}, found &().

P.S. Thanks in advance for making rust-analyzer a little less buggy. :)

@LikeLakers2 LikeLakers2 added the C-bug Category: bug label Jun 13, 2023
@lnicola
Copy link
Member

lnicola commented Jun 13, 2023

Duplicate of #15039, already fixed 😄.

Nice bug report, though, thanks.

@lnicola lnicola closed this as completed Jun 13, 2023
@LikeLakers2
Copy link
Author

LikeLakers2 commented Jun 13, 2023

Ah, my apologies, I missed that when searching for related issues. Glad to hear it's already fixed - now to wait for the rust-analyzer extension to update. :)

And thank you. I do feel it's a little excessive on how much info it gives, but I'd rather give too much information about a bug than not enough. Still, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants