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

type_repetition_in_bounds should pay attention to msrv when ?Sized bound is involved #8772

Closed
dtolnay opened this issue May 1, 2022 · 0 comments · Fixed by #10994
Closed
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dtolnay
Copy link
Member

dtolnay commented May 1, 2022

Lint Name

type_repetition_in_bounds

Reproducer

# .clippy.toml

msrv = "1.14.0"
// lib.rs

pub trait Trait<X, Y, Z> {}

pub fn f<T: ?Sized, U>(arg: usize)
where
    T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
    U: Clone + Sync + 'static,
{}
error: this type has already been used as a bound predicate
 --> src/lib.rs:7:5
  |
7 |     T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `-D clippy::type-repetition-in-bounds` implied by `-D clippy::pedantic`
  = help: consider combining the bounds: `T: Sized + Trait<Option<usize>, Box<[String]>, bool>`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds

Clippy prefers I guess one of the following signatures instead:

pub fn f<T, U>(arg: usize)
where
    T: ?Sized + Trait<Option<usize>, Box<[String]>, bool> + 'static,
    U: Clone + Sync + 'static

// or:

pub fn f<T: ?Sized + Trait<Option<usize>, Box<[String]>, bool> + 'static, U>(arg: usize)
where
    U: Clone + Sync + 'static

The first one is great on modern compilers, but is a parse error on Rust 1.14 and older. Meanwhile, the second is not an improvement in my opinion. The bounds next to a type parameter (as opposed to in a where-clause) are only meant to be used for small/simple bounds.

I believe clippy should not trigger type_repetition_in_bounds if the msrv is declared as 1.14.0 or older and the type parameter has a single bound of ?Sized, with all the rest of the bounds being in the where-clause.

Version

rustc 1.62.0-nightly (7c4b47696 2022-04-30)
binary: rustc
commit-hash: 7c4b47696907d64eff5621a64eb3c6e795a9ec77
commit-date: 2022-04-30
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

Additional Labels

No response

@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 1, 2022
bors added a commit that referenced this issue Jun 22, 2023
[`type_repetition_in_bounds`]: respect MSRV for combining bounds

Fixes #8772.

changelog: [`type_repetition_in_bounds`]: respect msrv for combining `?Sized` bound
@bors bors closed this as completed in ce0a48a Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant