Skip to content
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

Derived PartialEq not recognized for const-generic type when other PartialEq is present (type-mismatch) #13121

Closed
NyxCode opened this issue Aug 26, 2022 · 1 comment · Fixed by #13463
Labels
A-ty type system / type inference / traits / method resolution

Comments

@NyxCode
Copy link

NyxCode commented Aug 26, 2022

I think I discovered a pretty severe bug related to const-generics as they are available on stable.

rust-analyzer version: 1.65.0-nightly (7480389 2022-08-25)
rustc version: 1.63.0 (4b91a6ea7 2022-08-08)
relevant settings: n/a

#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
struct MyStruct<const X: usize>(u32);

impl<const X: usize> PartialEq<u16> for MyStruct<X> {
    fn eq(&self, v: &u16) -> bool {
        self.0 == *v as u32
    }
}

fn compare<const X: usize>(a: MyStruct<X>, b: MyStruct<X>) {
    let eq = a == b; // expected u16, found MyStruct<X> rust-analyzer[type-mismatch](https://rust-analyzer.github.io/manual.html#type-mismatch)
}

The error goes away if

  • the const-generic X is removed or
  • the PartialEq<u16> impl is removed
@bjorn3 bjorn3 added the A-ty type system / type inference / traits / method resolution label Aug 26, 2022
@NyxCode NyxCode changed the title Derived PartialEq not recognized for const-generic type when other PartialEq is present Derived PartialEq not recognized for const-generic type when other PartialEq is present (type-mismatch) Aug 26, 2022
@lowr
Copy link
Contributor

lowr commented Sep 29, 2022

Related: #11878, #11957

We currently ignore const parameters in certain situations. This should be fixed when we get generic params ordering aligned with chalk and remove the hack introduced in the PRs above.

bors added a commit that referenced this issue Oct 22, 2022
…=Veykril

Support const generics for builtin derive macro

Fixes #13121

We have been treating every generic parameter as type parameter during builtin derive macro expansion. This patch adds support for const generics in such expansions.
@bors bors closed this as completed in 19efa0b Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants