Skip to content

Commit

Permalink
Fix rust-lang#10504, don't lint on derived code
Browse files Browse the repository at this point in the history
  • Loading branch information
Centri3 committed Jun 5, 2023
1 parent b033883 commit 6ea7cd8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions clippy_lints/src/trait_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ impl TraitBounds {
SpanlessTy { ty: p.bounded_ty, cx },
p.bounds.iter().collect::<Vec<_>>()
);
if let TyKind::Path(qpath) = p.bounded_ty.kind;
if format!("{}:", rustc_hir_pretty::qpath_to_string(&qpath))
== format!("{}:", snippet(cx, p.bounded_ty.span, "_"));

then {
let trait_bounds = v
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/type_repetition_in_bounds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::type_repetition_in_bounds)]
#![allow(clippy::extra_unused_type_parameters)]

use serde::Deserialize;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

pub fn foo<T>(_t: T)
Expand Down Expand Up @@ -70,6 +71,20 @@ mod issue4326 {
}
}

// Extern macros shouldn't lint, again (see #10504)
mod issue10504 {
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::hash::Hash;

#[derive(Debug, Serialize, Deserialize)]
#[serde(bound(
serialize = "T: Serialize + Hash + Eq",
deserialize = "Box<T>: serde::de::DeserializeOwned + Hash + Eq"
))]
struct OpaqueParams<T: ?Sized + Debug>(std::marker::PhantomData<T>);
}

// Issue #7360
struct Foo<T, U>
where
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/type_repetition_in_bounds.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this type has already been used as a bound predicate
--> $DIR/type_repetition_in_bounds.rs:9:5
--> $DIR/type_repetition_in_bounds.rs:10:5
|
LL | T: Clone,
| ^^^^^^^^
Expand All @@ -12,23 +12,23 @@ LL | #![deny(clippy::type_repetition_in_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this type has already been used as a bound predicate
--> $DIR/type_repetition_in_bounds.rs:26:5
--> $DIR/type_repetition_in_bounds.rs:27:5
|
LL | Self: Copy + Default + Ord,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider combining the bounds: `Self: Clone + Copy + Default + Ord`

error: this type has already been used as a bound predicate
--> $DIR/type_repetition_in_bounds.rs:86:5
--> $DIR/type_repetition_in_bounds.rs:101:5
|
LL | T: Clone,
| ^^^^^^^^
|
= help: consider combining the bounds: `T: ?Sized + Clone`

error: this type has already been used as a bound predicate
--> $DIR/type_repetition_in_bounds.rs:91:5
--> $DIR/type_repetition_in_bounds.rs:106:5
|
LL | T: ?Sized,
| ^^^^^^^^^
Expand Down

0 comments on commit 6ea7cd8

Please sign in to comment.