rust/src/test/compile-fail/regions-fn-subtyping.rs

25 lines
943 B
Rust
Raw Normal View History

2012-05-31 19:41:01 -05:00
// Here, `f` is a function that takes a pointer `x` and a function
// `g`, where `g` requires its argument `y` to be in the same region
// that `x` is in.
fn has_same_region(f: fn(x: &a/int, g: fn(y: &a/int))) {
2012-05-31 19:41:01 -05:00
// Somewhat counterintuitively, this fails because, in
// `wants_two_regions`, the `g` argument needs to be able to
// accept any region. That is, the type that `has_same_region`
// expects is *not* a subtype of the type that `wants_two_regions`
// expects.
wants_two_regions(f); //~ ERROR mismatched types
2012-05-31 19:41:01 -05:00
}
fn wants_two_regions(_f: fn(x: &int, g: fn(y: &int))) {
2012-06-01 12:30:50 -05:00
// Suppose we were to write code here that passed some arbitrary
// &int and some arbitrary fn(&int) to whatever's passed in as _f.
// This would be fine as far as the type annotation on the formal
// parameter _f goes, but if _f were `f` we'd be in trouble since
// `f` can't handle those arguments.
2012-05-31 19:41:01 -05:00
}
fn main() {
}