test: Add lifetime binders and new-style lifetime parameters to the test suite

This commit is contained in:
Patrick Walton 2013-03-22 16:07:55 -07:00
parent 6d81307a9b
commit 66770d20b3
17 changed files with 47 additions and 47 deletions

View File

@ -20,7 +20,7 @@ fn to_shorter_lifetime(bi: contravariant<'r>) {
let bj: contravariant<'blk> = bi;
}
fn to_longer_lifetime(bi: contravariant<'r>) -> contravariant/&static {
fn to_longer_lifetime(bi: contravariant<'r>) -> contravariant<'static> {
bi //~ ERROR mismatched types
}

View File

@ -13,19 +13,19 @@
// You can upcast to a *smaller region* but not a larger one. This is
// the normal case.
struct contravariant {
struct contravariant<'self> {
f: @fn() -> &'self int
}
fn to_same_lifetime(bi: contravariant/&r) {
let bj: contravariant/&r = bi;
fn to_same_lifetime<'r>(bi: contravariant<'r>) {
let bj: contravariant<'r> = bi;
}
fn to_shorter_lifetime(bi: contravariant/&r) {
let bj: contravariant/&blk = bi;
fn to_shorter_lifetime<'r>(bi: contravariant<'r>) {
let bj: contravariant<'blk> = bi;
}
fn to_longer_lifetime(bi: contravariant/&r) -> contravariant/&static {
fn to_longer_lifetime<'r>(bi: contravariant<'r>) -> contravariant<'static> {
bi //~ ERROR mismatched types
}

View File

@ -16,15 +16,15 @@ struct covariant {
f: @fn(x: &'self int) -> int
}
fn to_same_lifetime(bi: covariant/&r) {
let bj: covariant/&r = bi;
fn to_same_lifetime<'r>(bi: covariant<'r>) {
let bj: covariant<'r> = bi;
}
fn to_shorter_lifetime(bi: covariant/&r) {
let bj: covariant/&blk = bi; //~ ERROR mismatched types
fn to_shorter_lifetime<'r>(bi: covariant<'r>) {
let bj: covariant<'blk> = bi; //~ ERROR mismatched types
}
fn to_longer_lifetime(bi: covariant/&r) -> covariant/&static {
fn to_longer_lifetime<'r>(bi: covariant<'r>) -> covariant<'static> {
bi
}

View File

@ -12,19 +12,19 @@
//
// You cannot convert between regions.
struct invariant {
struct invariant<'self> {
f: &'self fn(x: &'self int) -> &'self int
}
fn to_same_lifetime(bi: invariant<'r>) {
fn to_same_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'r> = bi;
}
fn to_shorter_lifetime(bi: invariant<'r>) {
fn to_shorter_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'blk> = bi; //~ ERROR mismatched types
}
fn to_longer_lifetime(bi: invariant<'r>) -> invariant/&static {
fn to_longer_lifetime<'r>(bi: invariant<'r>) -> invariant<'static> {
bi //~ ERROR mismatched types
}

View File

@ -8,19 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct invariant {
struct invariant<'self> {
f: @fn(x: @mut &'self int)
}
fn to_same_lifetime(bi: invariant/&r) {
let bj: invariant/&r = bi;
fn to_same_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'r> = bi;
}
fn to_shorter_lifetime(bi: invariant/&r) {
let bj: invariant/&blk = bi; //~ ERROR mismatched types
fn to_shorter_lifetime(bi: invariant<'r>) {
let bj: invariant<'blk> = bi; //~ ERROR mismatched types
}
fn to_longer_lifetime(bi: invariant/&r) -> invariant/&static {
fn to_longer_lifetime(bi: invariant<'r>) -> invariant<'static> {
bi //~ ERROR mismatched types
}

View File

@ -8,19 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct invariant {
struct invariant<'self> {
f: @fn() -> @mut &'self int
}
fn to_same_lifetime(bi: invariant/&r) {
let bj: invariant/&r = bi;
fn to_same_lifetime(bi: invariant<'r>) {
let bj: invariant<'r> = bi;
}
fn to_shorter_lifetime(bi: invariant/&r) {
let bj: invariant/&blk = bi; //~ ERROR mismatched types
fn to_shorter_lifetime(bi: invariant<'r>) {
let bj: invariant<'blk> = bi; //~ ERROR mismatched types
}
fn to_longer_lifetime(bi: invariant/&r) -> invariant/&static {
fn to_longer_lifetime(bi: invariant<'r>) -> invariant<'static> {
bi //~ ERROR mismatched types
}

View File

@ -8,19 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct invariant {
struct invariant<'self> {
f: @mut &'self int
}
fn to_same_lifetime(bi: invariant<'r>) {
fn to_same_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'r> = bi;
}
fn to_shorter_lifetime(bi: invariant<'r>) {
fn to_shorter_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'blk> = bi; //~ ERROR mismatched types
}
fn to_longer_lifetime(bi: invariant<'r>) -> invariant/&static {
fn to_longer_lifetime<'r>(bi: invariant<'r>) -> invariant<'static> {
bi //~ ERROR mismatched types
}

View File

@ -11,11 +11,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait get_ctxt {
trait get_ctxt<'self> {
fn get_ctxt(self) -> &'self uint;
}
fn make_gc1(gc: @get_ctxt/&a) -> @get_ctxt/&b {
fn make_gc1(gc: @get_ctxt<'a>) -> @get_ctxt<'b> {
return gc; //~ ERROR mismatched types: expected `@get_ctxt/&b` but found `@get_ctxt/&a`
}
@ -27,7 +27,7 @@ impl get_ctxt for Foo<'self> {
fn get_ctxt(&self) -> &'self uint { self.r }
}
fn make_gc2(foo: Foo/&a) -> @get_ctxt/&b {
fn make_gc2<'a,'b>(foo: Foo<'a>) -> @get_ctxt<'b> {
return @foo as @get_ctxt; //~ ERROR cannot infer an appropriate lifetime
}

View File

@ -14,7 +14,7 @@ fn foo() -> int {
struct Bar { f: &'self fn() -> int }
static b : Bar/&static = Bar { f: foo };
static b : Bar<'static> = Bar { f: foo };
pub fn main() {
fail_unless!((b.f)() == 0xca7f000d);

View File

@ -12,13 +12,13 @@ struct font {
fontbuf: &'self ~[u8],
}
pub impl font/&self {
pub impl<'self> font<'self> {
fn buf(&self) -> &'self ~[u8] {
self.fontbuf
}
}
fn font(fontbuf: &'r ~[u8]) -> font/&r {
fn font(fontbuf: &'r ~[u8]) -> font<'r> {
font {
fontbuf: fontbuf
}

View File

@ -14,7 +14,7 @@ struct defer {
}
#[unsafe_destructor]
impl Drop for defer/&self {
impl<'self> Drop for defer<'self> {
fn finalize(&self) {
unsafe {
*(self.b) = true;
@ -22,7 +22,7 @@ impl Drop for defer/&self {
}
}
fn defer(b: &'r mut bool) -> defer/&r {
fn defer<'r>(b: &'r mut bool) -> defer<'r> {
defer {
b: b
}

View File

@ -14,7 +14,7 @@ struct defer {
}
#[unsafe_destructor]
impl Drop for defer/&self {
impl<'self> Drop for defer<'self> {
fn finalize(&self) {
unsafe {
*(self.b) = true;
@ -22,7 +22,7 @@ impl Drop for defer/&self {
}
}
fn defer(b: &'r mut bool) -> defer/&r {
fn defer(b: &'r mut bool) -> defer<'r> {
defer {
b: b
}

View File

@ -12,7 +12,7 @@ struct CMap {
buf: &'self [u8],
}
fn CMap(buf: &'r [u8]) -> CMap/&r {
fn CMap<'r>(buf: &'r [u8]) -> CMap<'r> {
CMap {
buf: buf
}

View File

@ -12,7 +12,7 @@ struct closure_box {
cl: &'self fn(),
}
fn box_it(+x: &'r fn()) -> closure_box/&r {
fn box_it<'r>(+x: &'r fn()) -> closure_box<'r> {
closure_box {cl: x}
}

View File

@ -20,7 +20,7 @@ fn with(bi: &'r boxed_int) {
// Here, the upcast is allowed because the `boxed_int` type is
// contravariant with respect to `&r`. See also
// compile-fail/regions-infer-invariance-due-to-mutability.rs
let bi: &'blk boxed_int/&blk = bi;
let bi: &'blk boxed_int<'blk> = bi;
fail_unless!(*get(bi) == 22);
}

View File

@ -26,7 +26,7 @@ struct Ccx {
fn alloc(_bcx : &'a arena) -> &'a Bcx<'a> {
unsafe {
return cast::reinterpret_cast(
&libc::malloc(sys::size_of::<Bcx/&blk>() as libc::size_t));
&libc::malloc(sys::size_of::<Bcx<'blk>>() as libc::size_t));
}
}

View File

@ -16,7 +16,7 @@ fn box_it(+x: &'r fn()) -> closure_box<'r> {
closure_box {cl: x}
}
fn call_static_closure(cl: closure_box/&static) {
fn call_static_closure(cl: closure_box<'static>) {
(cl.cl)();
}