change region syntax to &r/T in place of &r.T

This commit is contained in:
Niko Matsakis 2012-07-12 09:36:56 -07:00
parent 1fe0d8d7d7
commit 90e435e808
28 changed files with 87 additions and 82 deletions

View file

@ -420,15 +420,20 @@ class parser {
}
}
// Parses something like "&x." (note the trailing dot)
fn parse_region_dot() -> @region {
// Parses something like "&x/" (note the trailing slash)
fn parse_region_with_sep() -> @region {
let name =
alt copy self.token {
token::IDENT(sid, _) if self.look_ahead(1u) == token::DOT {
self.bump(); self.bump();
some(self.get_str(sid))
token::IDENT(sid, _) => {
if self.look_ahead(1u) == token::DOT || // backwards compat
self.look_ahead(1u) == token::BINOP(token::SLASH) {
self.bump(); self.bump();
some(self.get_str(sid))
} else {
none
}
}
_ { none }
_ => { none }
};
self.region_from_name(name)
}
@ -495,7 +500,7 @@ class parser {
t
} else if self.token == token::BINOP(token::AND) {
self.bump();
let region = self.parse_region_dot();
let region = self.parse_region_with_sep();
let mt = self.parse_mt();
ty_rptr(region, mt)
} else if self.eat_keyword("pure") {

View file

@ -183,10 +183,10 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
ty_ptr(tm) { "*" + mt_to_str(cx, tm) }
ty_rptr(r, tm) {
let rs = region_to_str(cx, r);
if str::len(rs) == 1u {
if rs == "&" {
rs + mt_to_str(cx, tm)
} else {
rs + "." + mt_to_str(cx, tm)
rs + "/" + mt_to_str(cx, tm)
}
}
ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }

View file

@ -1,9 +1,9 @@
fn foo(a: int) {
let _p: &static.int = &a; //~ ERROR mismatched types
let _p: &static/int = &a; //~ ERROR mismatched types
}
fn bar(a: int) {
let _q: &blk.int = &a;
let _q: &blk/int = &a;
}
fn main() {

View file

@ -6,12 +6,12 @@ class dog {
}
fn chase_cat() {
let p: &static.mut uint = &mut self.cats_chased; //~ ERROR mismatched types
let p: &static/mut uint = &mut self.cats_chased; //~ ERROR mismatched types
*p += 1u;
}
fn chase_cat_2() {
let p: &blk.mut uint = &mut self.cats_chased;
let p: &blk/mut uint = &mut self.cats_chased;
*p += 1u;
}
}

View file

@ -7,7 +7,7 @@ class dog {
fn chase_cat() {
for uint::range(0u, 10u) |i| {
let p: &static.mut uint = &mut self.food; //~ ERROR mismatched types
let p: &static/mut uint = &mut self.food; //~ ERROR mismatched types
*p = 3u;
}
}

View file

@ -1,12 +1,12 @@
fn foo(cond: bool) {
let x = 5;
let mut y: &blk.int = &x;
let mut y: &blk/int = &x;
let mut z: &blk.int;
let mut z: &blk/int;
if cond {
z = &x;
} else {
let w: &blk.int = &x;
let w: &blk/int = &x;
z = w; //~ ERROR mismatched types
}
}

View file

@ -3,8 +3,8 @@
// checked.
enum an_enum = ∫
iface an_iface { fn foo() -> &self.int; }
class a_class { let x:&self.int; new(x:&self.int) { self.x = x; } }
iface an_iface { fn foo() -> &self/int; }
class a_class { let x:&self/int; new(x:&self/int) { self.x = x; } }
fn a_fn1(e: an_enum/&a) -> an_enum/&b {
ret e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`

View file

@ -1,9 +1,9 @@
enum ast/& {
enum ast {
num(uint),
add(&ast, &ast)
}
fn mk_add_bad1(x: &a.ast, y: &b.ast) -> ast/&a {
fn mk_add_bad1(x: &a/ast, y: &b/ast) -> ast/&a {
add(x, y) //~ ERROR mismatched types: expected `&a.ast/&a` but found `&b.ast/&b`
}

View file

@ -1,9 +1,9 @@
enum ast/& {
enum ast {
num(uint),
add(&ast, &ast)
}
fn mk_add_bad2(x: &a.ast, y: &a.ast, z: &ast) -> ast {
fn mk_add_bad2(x: &a/ast, y: &a/ast, z: &ast) -> ast {
add(x, y) //~ ERROR mismatched types: expected `ast/&` but found `ast/&a`
}

View file

@ -1,7 +1,7 @@
// 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))) {
fn has_same_region(f: fn(x: &a/int, g: fn(y: &a/int))) {
// 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`

View file

@ -1,16 +1,16 @@
// Should fail region checking, because g can only accept a pointer
// with lifetime r, and a is a pointer with unspecified lifetime.
fn not_ok_1(a: &uint) {
let mut g: fn@(x: &uint) = fn@(x: &r.uint) {};
let mut g: fn@(x: &uint) = fn@(x: &r/uint) {};
//~^ ERROR mismatched types
g(a);
}
// Should fail region checking, because g can only accept a pointer
// with lifetime r, and a is a pointer with lifetime s.
fn not_ok_2(s: &s.uint)
fn not_ok_2(s: &s/uint)
{
let mut g: fn@(x: &uint) = fn@(x: &r.uint) {};
let mut g: fn@(x: &uint) = fn@(x: &r/uint) {};
//~^ ERROR mismatched types
g(s);
}

View file

@ -11,7 +11,7 @@ impl of get_ctxt for has_ctxt {
// Here an error occurs because we used `&self` but
// the definition used `&`:
fn get_ctxt() -> &self.ctxt { //~ ERROR method `get_ctxt` has an incompatible type
fn get_ctxt() -> &self/ctxt { //~ ERROR method `get_ctxt` has an incompatible type
self.c
}

View file

@ -1,13 +1,13 @@
type ctxt = { v: uint };
iface get_ctxt {
fn get_ctxt() -> &self.ctxt;
fn get_ctxt() -> &self/ctxt;
}
type has_ctxt = { c: &ctxt };
impl of get_ctxt for has_ctxt {
fn get_ctxt() -> &self.ctxt { self.c }
fn get_ctxt() -> &self/ctxt { self.c }
}
fn make_gc() -> get_ctxt {

View file

@ -1,5 +1,5 @@
iface get_ctxt {
fn get_ctxt() -> &self.uint;
fn get_ctxt() -> &self/uint;
}
fn make_gc1(gc: get_ctxt/&a) -> get_ctxt/&b {

View file

@ -1,7 +1,7 @@
// xfail-test
const c_x: &blk.int = 22; //~ ERROR only the static region is allowed here
const c_y: &static.int = &22; //~ ERROR only the static region is allowed here
const c_x: &blk/int = 22; //~ ERROR only the static region is allowed here
const c_y: &static/int = &22; //~ ERROR only the static region is allowed here
fn main() {
}

View file

@ -3,11 +3,11 @@ enum yes0 {
}
enum yes1 {
x4(&self.uint)
x4(&self/uint)
}
enum yes2 {
x5(&foo.uint) //~ ERROR named regions other than `self` are not allowed as part of a type declaration
x5(&foo/uint) //~ ERROR named regions other than `self` are not allowed as part of a type declaration
}
fn main() {}

View file

@ -5,14 +5,14 @@ class yes0 {
}
class yes1 {
let x: &self.uint;
new(x: &self.uint) { self.x = x; }
let x: &self/uint;
new(x: &self/uint) { self.x = x; }
drop {}
}
class yes2 {
let x: &foo.uint; //~ ERROR named regions other than `self` are not allowed as part of a type declaration
new(x: &foo.uint) { self.x = x; } //~ ERROR named regions other than `self` are not allowed as part of a type declaration
let x: &foo/uint; //~ ERROR named regions other than `self` are not allowed as part of a type declaration
new(x: &foo/uint) { self.x = x; } //~ ERROR named regions other than `self` are not allowed as part of a type declaration
drop {}
}

View file

@ -3,11 +3,11 @@ type item_ty_yes0 = {
};
type item_ty_yes1 = {
x: &self.uint
x: &self/uint
};
type item_ty_yes2 = {
x: &foo.uint //~ ERROR named regions other than `self` are not allowed as part of a type declaration
x: &foo/uint //~ ERROR named regions other than `self` are not allowed as part of a type declaration
};
fn main() {}

View file

@ -11,7 +11,7 @@ impl methods for c {
}
fn set_f_bad(b: @b) {
self.f = b; //~ ERROR mismatched types: expected `@@&self.int` but found `@@&int`
self.f = b; //~ ERROR mismatched types: expected `@@&self/int` but found `@@&int`
}
}

View file

@ -2,7 +2,7 @@
// refers to self.
iface foo {
fn self_int() -> &self.int;
fn self_int() -> &self/int;
fn any_int() -> ∫
}

View file

@ -1,16 +1,16 @@
fn ignore<T>(t: T) {}
fn nested(x: &x.int) {
fn nested(x: &x/int) {
let y = 3;
let mut ay = &y;
ignore(fn&(z: &z.int) {
ignore(fn&(z: &z/int) {
ay = x;
ay = &y;
ay = z; //~ ERROR references with lifetime
});
ignore(fn&(z: &z.int) -> &z.int {
ignore(fn&(z: &z/int) -> &z/int {
if false { ret x; } //~ ERROR references with lifetime
if false { ret &y; } //~ ERROR references with lifetime
if false { ret ay; } //~ ERROR references with lifetime

View file

@ -1,6 +1,6 @@
// error-pattern: mismatched types
fn f(x : &a.int) -> &a.int {
fn f(x : &a/int) -> &a/int {
ret &3;
}

View file

@ -1,42 +1,42 @@
fn with<T>(t: T, f: fn(T)) { f(t) }
fn nested(x: &x.int) { // (1)
fn nested(x: &x/int) { // (1)
do with(
fn&(x: &x.int, // Refers to the region `x` at (1)
y: &y.int, // A fresh region `y` (2)
z: fn(x: &x.int, // Refers to `x` at (1)
y: &y.int, // Refers to `y` at (2)
z: &z.int) -> &z.int) // A fresh region `z` (3)
-> &x.int {
fn&(x: &x/int, // Refers to the region `x` at (1)
y: &y/int, // A fresh region `y` (2)
z: fn(x: &x/int, // Refers to `x` at (1)
y: &y/int, // Refers to `y` at (2)
z: &z/int) -> &z/int) // A fresh region `z` (3)
-> &x/int {
if false { ret z(x, x, x); } //~ ERROR mismatched types: expected `&y.int` but found `&x.int`
if false { ret z(x, x, y); } //~ ERROR mismatched types: expected `&y.int` but found `&x.int`
//~^ ERROR mismatched types: expected `&x.int` but found `&y.int`
if false { ret z(x, x, x); } //~ ERROR mismatched types: expected `&y/int` but found `&x/int`
if false { ret z(x, x, y); } //~ ERROR mismatched types: expected `&y/int` but found `&x/int`
//~^ ERROR mismatched types: expected `&x/int` but found `&y/int`
if false { ret z(x, y, x); }
if false { ret z(x, y, y); } //~ ERROR mismatched types: expected `&x.int` but found `&y.int`
if false { ret z(y, x, x); } //~ ERROR mismatched types: expected `&x.int` but found `&y.int`
//~^ ERROR mismatched types: expected `&y.int` but found `&x.int`
if false { ret z(y, x, y); } //~ ERROR mismatched types: expected `&x.int` but found `&y.int`
//~^ ERROR mismatched types: expected `&y.int` but found `&x.int`
//~^^ ERROR mismatched types: expected `&x.int` but found `&y.int`
if false { ret z(y, y, x); } //~ ERROR mismatched types: expected `&x.int` but found `&y.int`
if false { ret z(y, y, y); } //~ ERROR mismatched types: expected `&x.int` but found `&y.int`
//~^ ERROR mismatched types: expected `&x.int` but found `&y.int`
if false { ret z(x, y, y); } //~ ERROR mismatched types: expected `&x/int` but found `&y/int`
if false { ret z(y, x, x); } //~ ERROR mismatched types: expected `&x/int` but found `&y/int`
//~^ ERROR mismatched types: expected `&y/int` but found `&x/int`
if false { ret z(y, x, y); } //~ ERROR mismatched types: expected `&x/int` but found `&y/int`
//~^ ERROR mismatched types: expected `&y/int` but found `&x/int`
//~^^ ERROR mismatched types: expected `&x/int` but found `&y/int`
if false { ret z(y, y, x); } //~ ERROR mismatched types: expected `&x/int` but found `&y/int`
if false { ret z(y, y, y); } //~ ERROR mismatched types: expected `&x/int` but found `&y/int`
//~^ ERROR mismatched types: expected `&x/int` but found `&y/int`
fail;
}
) |foo| {
let a: &x.int = foo(x, x, |_x, _y, z| z );
let b: &x.int = foo(x, a, |_x, _y, z| z );
let c: &x.int = foo(a, a, |_x, _y, z| z );
let a: &x/int = foo(x, x, |_x, _y, z| z );
let b: &x/int = foo(x, a, |_x, _y, z| z );
let c: &x/int = foo(a, a, |_x, _y, z| z );
let z = 3i;
let d: &x.int = foo(x, x, |_x, _y, z| z );
let e: &x.int = foo(x, &z, |_x, _y, z| z );
let f: &x.int = foo(&z, &z, |_x, _y, z| z ); //~ ERROR mismatched types: expected `&x.int` but found
let d: &x/int = foo(x, x, |_x, _y, z| z );
let e: &x/int = foo(x, &z, |_x, _y, z| z );
let f: &x/int = foo(&z, &z, |_x, _y, z| z ); //~ ERROR mismatched types: expected `&x/int` but found
foo(x, &z, |x, _y, _z| x ); //~ ERROR mismatched types: expected `&z.int` but found `&x.int`
foo(x, &z, |_x, y, _z| y ); //~ ERROR mismatched types: expected `&z.int` but found `&<block at
foo(x, &z, |x, _y, _z| x ); //~ ERROR mismatched types: expected `&z/int` but found `&x/int`
foo(x, &z, |_x, y, _z| y ); //~ ERROR mismatched types: expected `&z/int` but found `&<block at
}
}

View file

@ -1,11 +1,11 @@
class font {
let fontbuf: &self.~[u8];
let fontbuf: &self/~[u8];
new(fontbuf: &self.~[u8]) {
new(fontbuf: &self/~[u8]) {
self.fontbuf = fontbuf;
}
fn buf() -> &self.~[u8] {
fn buf() -> &self/~[u8] {
self.fontbuf
}
}

View file

@ -1,7 +1,7 @@
class CMap {
let buf: &[u8];
new(buf: &self.[u8]) {
new(buf: &self/[u8]) {
self.buf = buf;
}
}

View file

@ -3,7 +3,7 @@ enum ast {
add(&ast, &ast)
}
fn mk_add_ok(x: &a.ast, y: &a.ast, z: &ast) -> ast/&a {
fn mk_add_ok(x: &a/ast, y: &a/ast, z: &ast) -> ast/&a {
add(x, y)
}

View file

@ -1,13 +1,13 @@
type ctxt = { v: uint };
iface get_ctxt {
fn get_ctxt() -> &self.ctxt;
fn get_ctxt() -> &self/ctxt;
}
type has_ctxt = { c: &ctxt };
impl of get_ctxt for has_ctxt {
fn get_ctxt() -> &self.ctxt {
fn get_ctxt() -> &self/ctxt {
self.c
}
}

View file

@ -1,7 +1,7 @@
type clam = { chowder: &int };
impl clam for clam {
fn get_chowder() -> &self.int { ret self.chowder; }
fn get_chowder() -> &self/int { ret self.chowder; }
}
fn main() {