rust/src/test/run-pass/regions-fn-subtyping.rs

37 lines
1.2 KiB
Rust
Raw Normal View History

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
2012-05-21 13:04:30 -07:00
// Issue #2263.
2013-08-17 08:37:42 -07:00
#[allow(dead_assignment)];
#[allow(unused_variable)];
2012-05-21 13:04:30 -07:00
// Should pass region checking.
2013-09-16 23:37:54 -07:00
fn ok(f: &fn(x: &uint)) {
2012-05-21 13:04:30 -07:00
// Here, g is a function that can accept a uint pointer with
// lifetime r, and f is a function that can accept a uint pointer
2012-05-29 10:52:32 -07:00
// with any lifetime. The assignment g = f should be OK (i.e.,
// f's type should be a subtype of g's type), because f can be
// used in any context that expects g's type. But this currently
// fails.
2013-09-16 23:37:54 -07:00
let mut g: &fn<'r>(y: &'r uint) = |x| { };
2012-05-21 13:04:30 -07:00
g = f;
}
// This version is the same as above, except that here, g's type is
// inferred.
2013-09-16 23:37:54 -07:00
fn ok_inferred(f: &fn(x: &uint)) {
let mut g: &fn<'r>(x: &'r uint) = |_| {};
2012-05-21 13:04:30 -07:00
g = f;
}
pub fn main() {
2012-05-21 13:04:30 -07:00
}