Skip to content

Commit f598bb7

Browse files
committed
Walk the left side of where bounds if the bounded type is not a generic parameter
1 parent 98363cb commit f598bb7

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

clippy_lints/src/extra_unused_type_parameters.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,13 @@ impl<'cx, 'tcx> Visitor<'tcx> for TypeWalker<'cx, 'tcx> {
246246
{
247247
self.ty_params.remove(&def_id);
248248
}
249+
} else {
250+
// If the bounded type isn't a generic param, but is instead a concrete generic
251+
// type, any params we find nested inside of it are being used as concrete types,
252+
// and can therefore can be considered used. So, we're fine to walk the left-hand
253+
// side of the where bound.
254+
walk_ty(self, predicate.bounded_ty);
249255
}
250-
// Only walk the right-hand side of where bounds
251256
for bound in predicate.bounds {
252257
walk_param_bound(self, bound);
253258
}

tests/ui/extra_unused_type_parameters.fixed

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,19 @@ with_span!(
113113
}
114114
);
115115

116+
mod issue11302 {
117+
use std::fmt::Debug;
118+
use std::marker::PhantomData;
119+
120+
#[derive(Debug)]
121+
struct Wrapper<T>(PhantomData<T>);
122+
123+
fn store<T: 'static>(v: &mut Vec<Box<dyn Debug>>)
124+
where
125+
Wrapper<T>: Debug,
126+
{
127+
v.push(Box::new(Wrapper(PhantomData)));
128+
}
129+
}
130+
116131
fn main() {}

tests/ui/extra_unused_type_parameters.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,19 @@ with_span!(
113113
}
114114
);
115115

116+
mod issue11302 {
117+
use std::fmt::Debug;
118+
use std::marker::PhantomData;
119+
120+
#[derive(Debug)]
121+
struct Wrapper<T>(PhantomData<T>);
122+
123+
fn store<T: 'static>(v: &mut Vec<Box<dyn Debug>>)
124+
where
125+
Wrapper<T>: Debug,
126+
{
127+
v.push(Box::new(Wrapper(PhantomData)));
128+
}
129+
}
130+
116131
fn main() {}

0 commit comments

Comments
 (0)