Skip to content

Commit 6ea7cd8

Browse files
committed
Fix rust-lang#10504, don't lint on derived code
1 parent b033883 commit 6ea7cd8

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

clippy_lints/src/trait_bounds.rs

+3
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ impl TraitBounds {
260260
SpanlessTy { ty: p.bounded_ty, cx },
261261
p.bounds.iter().collect::<Vec<_>>()
262262
);
263+
if let TyKind::Path(qpath) = p.bounded_ty.kind;
264+
if format!("{}:", rustc_hir_pretty::qpath_to_string(&qpath))
265+
== format!("{}:", snippet(cx, p.bounded_ty.span, "_"));
263266

264267
then {
265268
let trait_bounds = v

tests/ui/type_repetition_in_bounds.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![deny(clippy::type_repetition_in_bounds)]
22
#![allow(clippy::extra_unused_type_parameters)]
33

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

67
pub fn foo<T>(_t: T)
@@ -70,6 +71,20 @@ mod issue4326 {
7071
}
7172
}
7273

74+
// Extern macros shouldn't lint, again (see #10504)
75+
mod issue10504 {
76+
use serde::{Deserialize, Serialize};
77+
use std::fmt::Debug;
78+
use std::hash::Hash;
79+
80+
#[derive(Debug, Serialize, Deserialize)]
81+
#[serde(bound(
82+
serialize = "T: Serialize + Hash + Eq",
83+
deserialize = "Box<T>: serde::de::DeserializeOwned + Hash + Eq"
84+
))]
85+
struct OpaqueParams<T: ?Sized + Debug>(std::marker::PhantomData<T>);
86+
}
87+
7388
// Issue #7360
7489
struct Foo<T, U>
7590
where

tests/ui/type_repetition_in_bounds.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this type has already been used as a bound predicate
2-
--> $DIR/type_repetition_in_bounds.rs:9:5
2+
--> $DIR/type_repetition_in_bounds.rs:10:5
33
|
44
LL | T: Clone,
55
| ^^^^^^^^
@@ -12,23 +12,23 @@ LL | #![deny(clippy::type_repetition_in_bounds)]
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1313

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

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

3030
error: this type has already been used as a bound predicate
31-
--> $DIR/type_repetition_in_bounds.rs:91:5
31+
--> $DIR/type_repetition_in_bounds.rs:106:5
3232
|
3333
LL | T: ?Sized,
3434
| ^^^^^^^^^

0 commit comments

Comments
 (0)