]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/where-for-self.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / where-for-self.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that we can quantify lifetimes outside a constraint (i.e., including
12 // the self type) in a where clause.
13
14 // pretty-expanded FIXME #23616
15
16 use std::marker::PhantomFn;
17
18 static mut COUNT: u32 = 1;
19
20 trait Bar<'a>
21     : PhantomFn<&'a ()>
22 {
23     fn bar(&self);
24 }
25
26 trait Baz<'a>
27     : PhantomFn<&'a ()>
28 {
29     fn baz(&self);
30 }
31
32 impl<'a, 'b> Bar<'b> for &'a u32 {
33     fn bar(&self) {
34         unsafe { COUNT *= 2; }
35     }
36 }
37
38 impl<'a, 'b> Baz<'b> for &'a u32 {
39     fn baz(&self) {
40         unsafe { COUNT *= 3; }
41     }
42 }
43
44 // Test we can use the syntax for HRL including the self type.
45 fn foo1<T>(x: &T)
46     where for<'a, 'b> &'a T: Bar<'b>
47 {
48     x.bar()
49 }
50
51 // Test we can quantify multiple bounds (i.e., the precedence is sensible).
52 fn foo2<T>(x: &T)
53     where for<'a, 'b> &'a T: Bar<'b> + Baz<'b>
54 {
55     x.baz();
56     x.bar()
57 }
58
59 fn main() {
60     let x = 42;
61     foo1(&x);
62     foo2(&x);
63     unsafe {
64         assert!(COUNT == 12);
65     }
66 }