Skip to content

clippy::type_repetition_in_bounds triggers on derived code #10504

Closed
@RReverser

Description

@RReverser

Summary

clippy::type_repetition_in_bounds triggers on code generated by Serde derive when it clashes with bounds on the type itself.

Lint Name

type_repetition_in_bounds

Reproducer

I tried this code:

#[derive(Debug, Serialize, Deserialize)]
#[serde(bound(
    serialize = "ParamStr: Serialize + Hash + Eq",
    deserialize = "Box<ParamStr>: serde::de::DeserializeOwned + Hash + Eq"
))]
pub(crate) struct OpaqueParams<ParamStr: ?Sized + Debug>(
    pub(crate) IndexMap<Box<ParamStr>, String>,
);

I saw this happen:

warning: this type has already been used as a bound predicate
   --> [...]/src/params.rs:135:17
    |
135 |     serialize = "ParamStr: Serialize + Hash + Eq",
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: consider combining the bounds: `"ParamStr: Serialize + Hash + Eq": ?Sized + Debug + "ParamStr: Serialize + Hash + Eq" + "ParamStr: Serialize + Hash + Eq" + "ParamStr: Serialize + Hash + Eq"`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds

I expected to see this happen:

No error because this bound is used by derived code.

Version

rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.68.0
LLVM version: 15.0.6

Additional Labels

@rustbot label +T-macros

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-macrosType: Issues with macros and macro expansion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions