]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/regions-scope-chain-example.rs
e5ef88006c7df9925f52b9cee8a46b403c27d7c2
[rust.git] / src / test / run-pass / regions-scope-chain-example.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 // This is an example where the older inference algorithm failed. The
12 // specifics of why it failed are somewhat, but not entirely, tailed
13 // to the algorithm. Ultimately the problem is that when computing the
14 // mutual supertype of both sides of the `if` it would be faced with a
15 // choice of tightening bounds or unifying variables and it took the
16 // wrong path. The new algorithm avoids this problem and hence this
17 // example typechecks correctly.
18
19 enum ScopeChain<'a> {
20     Link(Scope<'a>),
21     End
22 }
23
24 type Scope<'a> = &'a ScopeChain<'a>;
25
26 struct OuterContext;
27
28 struct Context<'a> {
29     foo: &'a OuterContext
30 }
31
32 impl<'a> Context<'a> {
33     fn foo(&mut self, scope: Scope) {
34         let link = if 1 < 2 {
35             let l = ScopeChain::Link(scope);
36             self.take_scope(&l);
37             l
38         } else {
39             ScopeChain::Link(scope)
40         };
41         self.take_scope(&link);
42     }
43
44     fn take_scope(&mut self, x: Scope) {
45     }
46 }
47
48 fn main() { }