]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/regions-lifetime-nonfree-late-bound.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / regions-lifetime-nonfree-late-bound.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 a regression test for the ICE from issue #10846.
12 //
13 // The original issue causing the ICE: the LUB-computations during
14 // type inference were encountering late-bound lifetimes, and
15 // asserting that such lifetimes should have already been substituted
16 // with a concrete lifetime.
17 //
18 // However, those encounters were occurring within the lexical scope
19 // of the binding for the late-bound lifetime; that is, the late-bound
20 // lifetimes were perfectly valid.  The core problem was that the type
21 // folding code was over-zealously passing back all lifetimes when
22 // doing region-folding, when really all clients of the region-folding
23 // case only want to see FREE lifetime variables, not bound ones.
24
25 #![allow(unknown_features)]
26 #![feature(box_syntax)]
27
28 pub fn main() {
29     fn explicit() {
30         fn test<F>(_x: Option<Box<F>>) where F: FnMut(Box<for<'a> FnMut(&'a int)>) {}
31         test(Some(box |&mut: _f: Box<for<'a> FnMut(&'a int)>| {}));
32     }
33
34     // The code below is shorthand for the code above (and more likely
35     // to represent what one encounters in practice).
36     fn implicit() {
37         fn test<F>(_x: Option<Box<F>>) where F: FnMut(Box<        FnMut(&   int)>) {}
38         test(Some(box |&mut: _f: Box<        FnMut(&   int)>| {}));
39     }
40
41     explicit();
42     implicit();
43 }