rust/src/test/run-pass/regions-fn-subtyping.rs
Niko Matsakis 2a74fda316 Fix pretty-printer test failure by carrying the bound lifetime names through
the types.  Initially I thought it would be necessary to thread this data
through not only the AST but the types themselves, but then I remembered that
the pretty printer only cares about the AST.  Regardless, I have elected to
leave the changes to the types intact since they will eventually be needed.  I
left a few FIXMEs where it didn't seem worth finishing up since the code wasn't
crucial yet.
2013-03-27 11:35:04 -07:00

34 lines
1.1 KiB
Rust

// 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.
// Issue #2263.
// Should pass region checking.
fn ok(f: @fn(x: &uint)) {
// 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
// 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.
let mut g: @fn<'r>(y: &'r uint) = |x| { };
g = f;
}
// This version is the same as above, except that here, g's type is
// inferred.
fn ok_inferred(f: @fn(x: &uint)) {
let mut g: @fn<'r>(x: &'r uint) = |_| {};
g = f;
}
pub fn main() {
}