2020-06-22 07:57:03 -05:00
|
|
|
// build-fail
|
2022-05-17 09:18:40 -05:00
|
|
|
// compile-flags: -Copt-level=0 -Zpolymorphize=on
|
|
|
|
|
2020-07-16 11:52:23 -05:00
|
|
|
#![feature(rustc_attrs)]
|
2020-06-22 07:57:03 -05:00
|
|
|
|
|
|
|
// This test checks that `T` is considered used in `foo`, because it is used in a predicate for
|
|
|
|
// `I`, which is used.
|
|
|
|
|
2020-07-16 11:52:23 -05:00
|
|
|
#[rustc_polymorphize_error]
|
2020-06-22 07:57:03 -05:00
|
|
|
fn bar<I>() {
|
2020-07-16 11:52:23 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-06-22 07:57:03 -05:00
|
|
|
}
|
|
|
|
|
2020-07-16 11:52:23 -05:00
|
|
|
#[rustc_polymorphize_error]
|
2020-06-22 07:57:03 -05:00
|
|
|
fn foo<I, T>(_: I)
|
2020-08-20 05:42:56 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-06-22 07:57:03 -05:00
|
|
|
where
|
|
|
|
I: Iterator<Item = T>,
|
|
|
|
{
|
|
|
|
bar::<I>()
|
|
|
|
}
|
|
|
|
|
2020-08-14 06:33:20 -05:00
|
|
|
#[rustc_polymorphize_error]
|
|
|
|
fn baz<I, T>(_: I)
|
2020-08-20 05:42:56 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-08-14 06:33:20 -05:00
|
|
|
where
|
|
|
|
std::iter::Repeat<I>: Iterator<Item = T>,
|
|
|
|
{
|
|
|
|
bar::<I>()
|
|
|
|
}
|
|
|
|
|
|
|
|
// In addition, check that `I` is considered used in `next::{{closure}}`, because `T` is used and
|
|
|
|
// `T` is really just `I::Item`. `E` is used due to the fixed-point marking of predicates.
|
|
|
|
|
|
|
|
pub(crate) struct Foo<'a, I, E>(I, &'a E);
|
|
|
|
|
|
|
|
impl<'a, I, T: 'a, E> Iterator for Foo<'a, I, E>
|
|
|
|
where
|
|
|
|
I: Iterator<Item = &'a (T, E)>,
|
|
|
|
{
|
|
|
|
type Item = T;
|
|
|
|
|
|
|
|
#[rustc_polymorphize_error]
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
self.find(|_| true)
|
2020-08-20 05:42:56 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-08-14 06:33:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Furthermore, check that `B` is considered used because `C` is used, and that `A` is considered
|
|
|
|
// used because `B` is now used.
|
|
|
|
|
|
|
|
trait Baz<Z> {}
|
|
|
|
|
|
|
|
impl Baz<u16> for u8 {}
|
|
|
|
impl Baz<u32> for u16 {}
|
|
|
|
|
|
|
|
#[rustc_polymorphize_error]
|
|
|
|
fn quux<A, B, C: Default>() -> usize
|
2020-08-20 05:42:56 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-08-14 06:33:20 -05:00
|
|
|
where
|
|
|
|
A: Baz<B>,
|
|
|
|
B: Baz<C>,
|
|
|
|
{
|
|
|
|
std::mem::size_of::<C>()
|
|
|
|
}
|
|
|
|
|
2020-08-16 10:35:38 -05:00
|
|
|
// Finally, check that `F` is considered used because `G` is used when neither are in the self-ty
|
|
|
|
// of the predicate.
|
|
|
|
|
|
|
|
trait Foobar<F, G> {}
|
|
|
|
|
|
|
|
impl Foobar<u32, u32> for () {}
|
|
|
|
|
|
|
|
#[rustc_polymorphize_error]
|
|
|
|
fn foobar<F, G>() -> usize
|
2020-08-20 05:42:56 -05:00
|
|
|
//~^ ERROR item has unused generic parameters
|
2020-08-16 10:35:38 -05:00
|
|
|
where
|
|
|
|
(): Foobar<F, G>,
|
|
|
|
{
|
|
|
|
std::mem::size_of::<G>()
|
|
|
|
}
|
|
|
|
|
2020-06-22 07:57:03 -05:00
|
|
|
fn main() {
|
|
|
|
let x = &[2u32];
|
|
|
|
foo(x.iter());
|
2020-08-14 06:33:20 -05:00
|
|
|
baz(x.iter());
|
|
|
|
|
|
|
|
let mut a = Foo([(1u32, 1u16)].iter(), &1u16);
|
|
|
|
let _ = a.next();
|
|
|
|
|
|
|
|
let _ = quux::<u8, u16, u32>();
|
2020-08-16 10:35:38 -05:00
|
|
|
|
|
|
|
let _ = foobar::<u32, u32>();
|
2020-06-22 07:57:03 -05:00
|
|
|
}
|