]> git.lizzy.rs Git - rust.git/blob - src/test/ui/self/where-for-self.rs
Update ui tests
[rust.git] / src / test / ui / self / where-for-self.rs
1 // run-pass
2 // Test that we can quantify lifetimes outside a constraint (i.e., including
3 // the self type) in a where clause.
4
5
6 static mut COUNT: u32 = 1;
7
8 trait Bar<'a> {
9     fn bar(&self);
10 }
11
12 trait Baz<'a>
13 {
14     fn baz(&self);
15 }
16
17 impl<'a, 'b> Bar<'b> for &'a u32 {
18     fn bar(&self) {
19         unsafe { COUNT *= 2; }
20     }
21 }
22
23 impl<'a, 'b> Baz<'b> for &'a u32 {
24     fn baz(&self) {
25         unsafe { COUNT *= 3; }
26     }
27 }
28
29 // Test we can use the syntax for HRL including the self type.
30 fn foo1<T>(x: &T)
31     where for<'a, 'b> &'a T: Bar<'b>
32 {
33     x.bar()
34 }
35
36 // Test we can quantify multiple bounds (i.e., the precedence is sensible).
37 fn foo2<T>(x: &T)
38     where for<'a, 'b> &'a T: Bar<'b> + Baz<'b>
39 {
40     x.baz();
41     x.bar()
42 }
43
44 fn main() {
45     let x = 42;
46     foo1(&x);
47     foo2(&x);
48     unsafe {
49         assert_eq!(COUNT, 12);
50     }
51 }