duplicated_attributes: false positive with apistos crate

Open
#13,238 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
tooling

Research direction

Start by reproducing the duplicated_attributes warning with the apistos ErrorResponse example in service/api/error_response.rs, then trace the duplicated_attributes lint entry point and its handling of generated attributes. Done means the three distinct status attributes no longer produce warnings while genuine duplicates remain reported.

Written by the indexing model from the issue text.

Description

C-bug I-false-positive
Summary

The duplicated_attributes lint yields false positives when using the apistos crate for OpenAPI documentation.

Lint Name

duplicated_attributes

Reproducer

I tried this code:

#[derive(Debug, Serialize, JsonSchema, ApiErrorComponent)]
#[openapi_error(
    status(code = 400, description = "An invalid request has been made."),
    status(code = 404, description = "The specified resource has not been found."),
    status(code = 500, description = "An internal server error occurred.")
)]
pub enum ErrorResponse {
    BadRequest(String),
    InternalServerError(String),
    NotFound(String),
}

I saw this happen:

warning: duplicated attribute
  --> service/src/api/error_response.rs:12:12
   |
12 |     status(code = 404, description = "The specified resource has not been found."),
   |            ^^^^^^^^^^
   |
note: first defined here
  --> service/src/api/error_response.rs:11:12
   |
11 |     status(code = 400, description = "An invalid request has been made."),
   |            ^^^^^^^^^^
help: remove this attribute
  --> service/src/api/error_response.rs:12:12
   |
12 |     status(code = 404, description = "The specified resource has not been found."),
   |            ^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
   = note: `-W clippy::duplicated-attributes` implied by `-W clippy::all`
   = help: to override `-W clippy::all` add `#[allow(clippy::duplicated_attributes)]`

I expected to see this happen:

No warnings should be emitted.

Version
rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: aarch64-apple-darwin
release: 1.80.0
LLVM version: 18.1.7
Additional Labels

No response

Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-lang/rust-clippy

All issues in rust-lang/rust-clippy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.