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