]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/regions-scope-chain-example.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[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 // pretty-expanded FIXME #23616
20
21 enum ScopeChain<'a> {
22     Link(Scope<'a>),
23     End
24 }
25
26 type Scope<'a> = &'a ScopeChain<'a>;
27
28 struct OuterContext;
29
30 struct Context<'a> {
31     foo: &'a OuterContext
32 }
33
34 impl<'a> Context<'a> {
35     fn foo(&mut self, scope: Scope) {
36         let link = if 1 < 2 {
37             let l = ScopeChain::Link(scope);
38             self.take_scope(&l);
39             l
40         } else {
41             ScopeChain::Link(scope)
42         };
43         self.take_scope(&link);
44     }
45
46     fn take_scope(&mut self, x: Scope) {
47     }
48 }
49
50 fn main() { }