rust/src/test/compile-fail/pure-subtyping.rs
Niko Matsakis b0ed151539 Cleanup how we handle proto in types, remove unsound subtyping
Fixes #1896 which was never truly fixed, just masked.
The given tests would have failed had they used `~fn()` and
not `@fn()`.  They now result in compilation errors.

Fixes #2978.

Necessary first step for #2202, #2263.
2012-11-06 08:56:29 -08:00

39 lines
1.3 KiB
Rust

// Test rules governing higher-order pure fns.
fn take<T>(_v: T) {}
fn assign_to_pure(x: pure fn(), y: fn(), z: unsafe fn()) {
take::<pure fn()>(x);
take::<pure fn()>(y); //~ ERROR expected pure fn but found impure fn
take::<pure fn()>(z); //~ ERROR expected pure fn but found unsafe fn
}
fn assign_to_impure(x: pure fn(), y: fn(), z: unsafe fn()) {
take::<fn()>(x);
take::<fn()>(y);
take::<fn()>(z); //~ ERROR expected impure fn but found unsafe fn
}
fn assign_to_unsafe(x: pure fn(), y: fn(), z: unsafe fn()) {
take::<unsafe fn()>(x);
take::<unsafe fn()>(y);
take::<unsafe fn()>(z);
}
fn assign_to_pure2(x: pure fn@(), y: fn@(), z: unsafe fn@()) {
take::<pure fn()>(x);
take::<pure fn()>(y); //~ ERROR expected pure fn but found impure fn
take::<pure fn()>(z); //~ ERROR expected pure fn but found unsafe fn
take::<pure fn~()>(x); //~ ERROR expected ~ closure, found @ closure
take::<pure fn~()>(y); //~ ERROR expected ~ closure, found @ closure
take::<pure fn~()>(z); //~ ERROR expected ~ closure, found @ closure
take::<unsafe fn~()>(x); //~ ERROR expected ~ closure, found @ closure
take::<unsafe fn~()>(y); //~ ERROR expected ~ closure, found @ closure
take::<unsafe fn~()>(z); //~ ERROR expected ~ closure, found @ closure
}
fn main() {
}