]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/hrtb-type-outlives.rs
Imported Upstream version 1.3.0+dfsg1
[rustc.git] / src / test / run-pass / hrtb-type-outlives.rs
1 // Copyright 2014 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 what happens when a HR obligation is applied to an impl with
12 // "outlives" bounds. Currently we're pretty conservative here; this
13 // will probably improve in time.
14
15 trait Foo<X> {
16 fn foo(&self, x: X) { }
17 }
18
19 fn want_foo<T>()
20 where T : for<'a> Foo<&'a isize>
21 {
22 }
23
24 ///////////////////////////////////////////////////////////////////////////
25 // Expressed as a where clause
26
27 struct SomeStruct<X> {
28 x: X
29 }
30
31 impl<'a,X> Foo<&'a isize> for SomeStruct<X>
32 where X : 'a
33 {
34 }
35
36 fn one() {
37 want_foo::<SomeStruct<usize>>();
38 }
39
40 ///////////////////////////////////////////////////////////////////////////
41 // Expressed as shorthand
42
43 struct AnotherStruct<X> {
44 x: X
45 }
46
47 impl<'a,X:'a> Foo<&'a isize> for AnotherStruct<X>
48 {
49 }
50
51 fn two() {
52 want_foo::<AnotherStruct<usize>>();
53 }
54
55 fn main() { }