]> git.lizzy.rs Git - rust.git/blob - src/test/ui/polymorphization/predicates.rs
Rollup merge of #75485 - RalfJung:pin, r=nagisa
[rust.git] / src / test / ui / polymorphization / predicates.rs
1 // build-fail
2 // compile-flags:-Zpolymorphize=on
3 #![feature(rustc_attrs)]
4
5 // This test checks that `T` is considered used in `foo`, because it is used in a predicate for
6 // `I`, which is used.
7
8 #[rustc_polymorphize_error]
9 fn bar<I>() {
10     //~^ ERROR item has unused generic parameters
11 }
12
13 #[rustc_polymorphize_error]
14 fn foo<I, T>(_: I)
15 where
16     I: Iterator<Item = T>,
17 {
18     bar::<I>()
19 }
20
21 #[rustc_polymorphize_error]
22 fn baz<I, T>(_: I)
23 where
24     std::iter::Repeat<I>: Iterator<Item = T>,
25 {
26     bar::<I>()
27 }
28
29 // In addition, check that `I` is considered used in `next::{{closure}}`, because `T` is used and
30 // `T` is really just `I::Item`. `E` is used due to the fixed-point marking of predicates.
31
32 pub(crate) struct Foo<'a, I, E>(I, &'a E);
33
34 impl<'a, I, T: 'a, E> Iterator for Foo<'a, I, E>
35 where
36     I: Iterator<Item = &'a (T, E)>,
37 {
38     type Item = T;
39
40     #[rustc_polymorphize_error]
41     fn next(&mut self) -> Option<Self::Item> {
42         self.find(|_| true)
43     }
44 }
45
46 // Furthermore, check that `B` is considered used because `C` is used, and that `A` is considered
47 // used because `B` is now used.
48
49 trait Baz<Z> {}
50
51 impl Baz<u16> for u8 {}
52 impl Baz<u32> for u16 {}
53
54 #[rustc_polymorphize_error]
55 fn quux<A, B, C: Default>() -> usize
56 where
57     A: Baz<B>,
58     B: Baz<C>,
59 {
60     std::mem::size_of::<C>()
61 }
62
63 fn main() {
64     let x = &[2u32];
65     foo(x.iter());
66     baz(x.iter());
67
68     let mut a = Foo([(1u32, 1u16)].iter(), &1u16);
69     let _ = a.next();
70
71     let _ = quux::<u8, u16, u32>();
72 }