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

Implement default members implements PartialEq::ne incorrectly #12779

Closed
awused opened this issue Jul 17, 2022 · 1 comment · Fixed by #12821
Closed

Implement default members implements PartialEq::ne incorrectly #12779

awused opened this issue Jul 17, 2022 · 1 comment · Fixed by #12821
Labels
A-assists C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@awused
Copy link

awused commented Jul 17, 2022

rust-analyzer version: rust-analyzer 0.0.0 (5342f47 2022-07-09)

rustc version: rustc 1.62.0 (a8314ef7d 2022-06-27)

relevant settings: Neovim with coc-rust-analyzer

I tried implement default members on some code by mistake, but got surprising results. Reproduction:

struct SomeStruct {
    data: Arc<Vec<u8>>,
    field: (u32, u32),
}

impl PartialEq for SomeStruct {
}

It will generate this ne method:

impl PartialEq for SomeStruct {
    fn ne(&self, other: &Self) -> bool {
        self.data == other.data && self.field == other.field
    }
}

The implement missing members works as expected for eq

@lnicola lnicola added S-actionable Someone could pick this issue up and work on it right now A-assists C-bug Category: bug labels Jul 17, 2022
@lnicola
Copy link
Member

lnicola commented Jul 17, 2022

I think this happens around

fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
, which doesn't seem to actually look at what method it's implementing.

@bors bors closed this as completed in c001b9c Jul 20, 2022
bors added a commit that referenced this issue Jul 24, 2022
…ykril

fix: don't replace default members' body

cc #12779, #12821
addresses #12821 (comment)

`gen_trait_fn_body()` only attempts to implement required trait member functions, so we shouldn't call it for `Implement default members` assist.

This patch also documents the precondition of `gen_trait_fn_body()` and inserts `debug_assert!`, but I'm not entirely sure if the assertions are appropriate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants