Skip to content

Clippy warnings in auto generated code: derive-partial-eq-without-eq #1261

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

Open
arvid-norlander opened this issue Mar 21, 2025 · 2 comments
Open

Comments

@arvid-norlander
Copy link

I'm getting many instances of clippy::derive-partial-eq-without-eq (an non-default lint that I like to enable for my code) for auto-generated code from prost/prost-build. E.g.

warning: you are deriving `PartialEq` and can implement `Eq`
   --> .../target/debug/build/crate_name-8fbbd81e799a35b3/out/analysis.rs:216:17
    |
216 | #[derive(Clone, PartialEq, ::prost::Message)]
    |                 ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq`

This happens on for example the following protobuf code (which comes from the bazel project):

syntax = "proto3";

// ...

// A set of fragment options.
message FragmentOptions {
  // The name of this set of fragment options.
  string name = 1;

  // The options themselves, in sorted order by name.
  repeated Option options = 2;
}

// A fragment option.
message Option {
  // The name of the option.
  optional string name = 1;

  // The value of the option.
  optional string value = 2;
}

For some reason Prost marks Option as implementing Eq, but not FragmentOptions. Which triggers clippy. And I think clippy is right in this case.

Note that there is a workaround available:

mod proto {
    #![allow(clippy::derive_partial_eq_without_eq)]
    #![allow(clippy::doc_lazy_continuation)]
    #![allow(clippy::enum_variant_names)]
    // ...
    include!(concat!(env!("OUT_DIR"), "/includes.rs"));
}

Most of those are reasonable to ignore for protobuf generated code, but derive_partial_eq_without_eq looks like an actual problem to my eye in the generated code.

@caspermeijn
Copy link
Collaborator

I did some work to automatically derive Eq where possible in #1175

That has not yet been released. Can you verify the clippy warnings are fixed on the main branch of prost-build?

@arvid-norlander
Copy link
Author

arvid-norlander commented Apr 15, 2025

I tried that, using commit fcf610e, but I still get a bunch of these warnings, including the one from the example snippet above.

I did this using

[patch.crates-io]
prost-build = { git = 'https://github.com/tokio-rs/prost.git' }

It seems it was correctly using the newer version:

   Compiling prost-derive v0.13.5 (https://github.com/tokio-rs/prost.git#fcf610ed)
   Compiling prost v0.13.5 (https://github.com/tokio-rs/prost.git#fcf610ed)
   Compiling prost-types v0.13.5 (https://github.com/tokio-rs/prost.git#fcf610ed)
   Compiling prost-build v0.13.5 (https://github.com/tokio-rs/prost.git#fcf610ed)

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

No branches or pull requests

2 participants