Auto merge of #11484 - mkrasnitski:fix-11302, r=Jarcho
[`extra_unused_type_parameters`]: Fix edge case FP for parameters in where bounds Generic parameters can end up being used on the left side of where-bounds if they are not directly bound but instead appear nested in some concrete generic type. Therefore, we should walk the left side of where bounds, but only if the bounded type is *not* a generic param, in which case we still need to ignore the bound. Fixes #11302 changelog: [`extra_unused_type_parameters`]: Fix edge case false positive for parameters in where bounds
This commit is contained in:
commit
e609279b2c
@ -246,8 +246,13 @@ impl<'cx, 'tcx> Visitor<'tcx> for TypeWalker<'cx, 'tcx> {
|
||||
{
|
||||
self.ty_params.remove(&def_id);
|
||||
}
|
||||
} else {
|
||||
// If the bounded type isn't a generic param, but is instead a concrete generic
|
||||
// type, any params we find nested inside of it are being used as concrete types,
|
||||
// and can therefore can be considered used. So, we're fine to walk the left-hand
|
||||
// side of the where bound.
|
||||
walk_ty(self, predicate.bounded_ty);
|
||||
}
|
||||
// Only walk the right-hand side of where bounds
|
||||
for bound in predicate.bounds {
|
||||
walk_param_bound(self, bound);
|
||||
}
|
||||
|
@ -113,4 +113,19 @@ with_span!(
|
||||
}
|
||||
);
|
||||
|
||||
mod issue11302 {
|
||||
use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Wrapper<T>(PhantomData<T>);
|
||||
|
||||
fn store<T: 'static>(v: &mut Vec<Box<dyn Debug>>)
|
||||
where
|
||||
Wrapper<T>: Debug,
|
||||
{
|
||||
v.push(Box::new(Wrapper(PhantomData)));
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -113,4 +113,19 @@ with_span!(
|
||||
}
|
||||
);
|
||||
|
||||
mod issue11302 {
|
||||
use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Wrapper<T>(PhantomData<T>);
|
||||
|
||||
fn store<T: 'static>(v: &mut Vec<Box<dyn Debug>>)
|
||||
where
|
||||
Wrapper<T>: Debug,
|
||||
{
|
||||
v.push(Box::new(Wrapper(PhantomData)));
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user