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