]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/hrtb-type-outlives.rs
7bb74d6b03a33e97b4606a7082d9823aaef9075e
[rustc.git] / src / test / compile-fail / 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 // In fact there is no good reason for this to be an error, but
38 // whatever, I'm mostly concerned it doesn't ICE right now:
39 want_foo::<SomeStruct<usize>>();
40 //~^ ERROR requirement `for<'a> usize : 'a` is not satisfied
41 }
42
43 ///////////////////////////////////////////////////////////////////////////
44 // Expressed as shorthand
45
46 struct AnotherStruct<X> {
47 x: X
48 }
49
50 impl<'a,X:'a> Foo<&'a isize> for AnotherStruct<X>
51 {
52 }
53
54 fn two() {
55 want_foo::<AnotherStruct<usize>>();
56 //~^ ERROR requirement `for<'a> usize : 'a` is not satisfied
57 }
58
59 fn main() { }