]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-scope-chain-example.rs
Rollup merge of #89468 - FabianWolff:issue-89358, r=jackh726
[rust.git] / src / test / ui / regions / regions-scope-chain-example.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 // This is an example where the older inference algorithm failed. The
5 // specifics of why it failed are somewhat, but not entirely, tailed
6 // to the algorithm. Ultimately the problem is that when computing the
7 // mutual supertype of both sides of the `if` it would be faced with a
8 // choice of tightening bounds or unifying variables and it took the
9 // wrong path. The new algorithm avoids this problem and hence this
10 // example typechecks correctly.
11
12 // pretty-expanded FIXME #23616
13
14 enum ScopeChain<'a> {
15     Link(Scope<'a>),
16     End
17 }
18
19 type Scope<'a> = &'a ScopeChain<'a>;
20
21 struct OuterContext;
22
23 struct Context<'a> {
24     foo: &'a OuterContext
25 }
26
27 impl<'a> Context<'a> {
28     fn foo(&mut self, scope: Scope) {
29         let link = if 1 < 2 {
30             let l = ScopeChain::Link(scope);
31             self.take_scope(&l);
32             l
33         } else {
34             ScopeChain::Link(scope)
35         };
36         self.take_scope(&link);
37     }
38
39     fn take_scope(&mut self, x: Scope) {
40     }
41 }
42
43 fn main() { }