rust-embed icon indicating copy to clipboard operation
rust-embed copied to clipboard

Clippy warning for same_name_method on generated file

Open Zacho2 opened this issue 2 years ago • 2 comments

Clippy warns on same_name_method because the generated code has two methods with the same name: one from a trait, another not from trait (get()/iter()).

I made a simple example to reproduce the issue: https://github.com/Zacho2/rustembed-clippy. This is basically the same as rust-embed/examples/basic.rs.

Example output from clippy:

$ cargo clippy -- -W clippy::same_name_method
    Checking rustembed-clippy v0.1.0 (/home/Documents/src/rustembed-clippy)
warning: method's name is the same as an existing method in a trait
 --> src/main.rs:3:10
  |
3 | #[derive(RustEmbed)]
  |          ^^^^^^^^^
  |
note: existing `get` defined here
 --> src/main.rs:3:10
  |
3 | #[derive(RustEmbed)]
  |          ^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#same_name_method
  = note: requested on the command line with `-W clippy::same-name-method`
  = note: this warning originates in the derive macro `RustEmbed` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `rustembed-clippy` (bin "rustembed-clippy") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s

It seems like one option is to add #[allow(clippy::same_name_method)] to the generated code. Maybe there's another option where we can fold the generated code into one get/iter method.

Zacho2 avatar Feb 05 '23 20:02 Zacho2

Unless we make a breaking change / major version, we can't remove the non-trait methods. I'd accept a PR that adds the allow attribute to the generated code.

AzureMarker avatar Feb 08 '23 02:02 AzureMarker

Alright, I plan to submit a PR for the allow attribute shortly.

Zacho2 avatar Feb 10 '23 03:02 Zacho2