]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/regions-fn-subtyping.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / regions-fn-subtyping.rs
1 // Copyright 2012 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 // Issue #2263.
12
13 // pretty-expanded FIXME #23616
14
15 #![allow(dead_assignment)]
16 #![allow(unused_variable)]
17 #![allow(unknown_features)]
18
19 // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
20
21 // Should pass region checking.
22 fn ok(f: Box<FnMut(&uint)>) {
23     // Here, g is a function that can accept a uint pointer with
24     // lifetime r, and f is a function that can accept a uint pointer
25     // with any lifetime.  The assignment g = f should be OK (i.e.,
26     // f's type should be a subtype of g's type), because f can be
27     // used in any context that expects g's type.  But this currently
28     // fails.
29     let mut g: Box<for<'r> FnMut(&'r uint)> = Box::new(|x| { });
30     g = f;
31 }
32
33 // This version is the same as above, except that here, g's type is
34 // inferred.
35 fn ok_inferred(f: Box<FnMut(&uint)>) {
36     let mut g: Box<for<'r> FnMut(&'r uint)> = Box::new(|_| {});
37     g = f;
38 }
39
40 pub fn main() {
41 }