//@ build-fail //@ compile-flags: -Copt-level=0 -Zpolymorphize=on #![feature(rustc_attrs)] // This test checks that `T` is considered used in `foo`, because it is used in a predicate for // `I`, which is used. #[rustc_polymorphize_error] fn bar() { //~^ ERROR item has unused generic parameters } #[rustc_polymorphize_error] fn foo(_: I) //~^ ERROR item has unused generic parameters where I: Iterator, { bar::() } #[rustc_polymorphize_error] fn baz(_: I) //~^ ERROR item has unused generic parameters where std::iter::Repeat: Iterator, { bar::() } // 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, { type Item = T; #[rustc_polymorphize_error] fn next(&mut self) -> Option { self.find(|_| true) //~^ ERROR item has unused generic parameters } } // Furthermore, check that `B` is considered used because `C` is used, and that `A` is considered // used because `B` is now used. trait Baz {} impl Baz for u8 {} impl Baz for u16 {} #[rustc_polymorphize_error] fn quux() -> usize //~^ ERROR item has unused generic parameters where A: Baz, B: Baz, { std::mem::size_of::() } // Finally, check that `F` is considered used because `G` is used when neither are in the self-ty // of the predicate. trait Foobar {} impl Foobar for () {} #[rustc_polymorphize_error] fn foobar() -> usize //~^ ERROR item has unused generic parameters where (): Foobar, { std::mem::size_of::() } fn main() { let x = &[2u32]; foo(x.iter()); baz(x.iter()); let mut a = Foo([(1u32, 1u16)].iter(), &1u16); let _ = a.next(); let _ = quux::(); let _ = foobar::(); }