auto merge of #5483 : pcwalton/rust/static-syntax, r=graydon

r? @nikomatsakis
This commit is contained in:
bors 2013-03-22 11:21:48 -07:00
commit b6f9aa1fd7
14 changed files with 60 additions and 57 deletions

View File

@ -376,7 +376,7 @@ pub fn check_bounds(cx: Context,
ty::bound_durable => {
if !kind.is_durable(cx.tcx) {
missing.push("&static");
missing.push("'static");
}
}
@ -467,7 +467,7 @@ pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool {
match ty::get(ty).sty {
ty::ty_param(*) => {
tcx.sess.span_err(sp, ~"value may contain borrowed \
pointers; use `&static` bound");
pointers; use `'static` bound");
}
_ => {
tcx.sess.span_err(sp, ~"value may contain borrowed \

View File

@ -1404,7 +1404,7 @@ pub fn substs_to_str(cx: ctxt, substs: &substs) -> ~str {
pub fn param_bound_to_str(cx: ctxt, pb: &param_bound) -> ~str {
match *pb {
bound_copy => ~"copy",
bound_durable => ~"&static",
bound_durable => ~"'static",
bound_owned => ~"owned",
bound_const => ~"const",
bound_trait(t) => ::util::ppaux::ty_to_str(cx, t)

View File

@ -2704,49 +2704,52 @@ pub impl Parser {
let mut result = opt_vec::Empty;
loop {
if self.eat(&token::BINOP(token::AND)) {
if self.eat_keyword(&~"static") {
result.push(RegionTyParamBound);
} else {
self.span_err(*self.span,
~"`&static` is the only permissible \
region bound here");
match *self.token {
token::LIFETIME(lifetime) => {
if str::eq_slice(*self.id_to_str(lifetime), "static") {
result.push(RegionTyParamBound);
} else {
self.span_err(*self.span,
~"`'static` is the only permissible \
region bound here");
}
self.bump();
}
} else if is_ident(&*self.token) {
let maybe_bound = match *self.token {
token::IDENT(copy sid, _) => {
match *self.id_to_str(sid) {
~"send" |
~"copy" |
~"const" |
~"owned" => {
self.obsolete(
*self.span,
ObsoleteLowerCaseKindBounds);
token::IDENT(*) => {
let maybe_bound = match *self.token {
token::IDENT(copy sid, _) => {
match *self.id_to_str(sid) {
~"send" |
~"copy" |
~"const" |
~"owned" => {
self.obsolete(
*self.span,
ObsoleteLowerCaseKindBounds);
// Bogus value, but doesn't matter, since
// is an error
Some(TraitTyParamBound(
self.mk_ty_path(sid)))
// Bogus value, but doesn't matter, since
// is an error
Some(TraitTyParamBound(
self.mk_ty_path(sid)))
}
_ => None
}
_ => None
}
_ => fail!()
};
match maybe_bound {
Some(bound) => {
self.bump();
result.push(bound);
}
None => {
let ty = self.parse_ty(false);
result.push(TraitTyParamBound(ty));
}
}
_ => fail!()
};
match maybe_bound {
Some(bound) => {
self.bump();
result.push(bound);
}
None => {
let ty = self.parse_ty(false);
result.push(TraitTyParamBound(ty));
}
}
} else {
break;
_ => break,
}
if self.eat(&token::BINOP(token::PLUS)) {

View File

@ -1755,7 +1755,7 @@ pub fn print_bounds(s: @ps, bounds: @OptVec<ast::TyParamBound>) {
match *bound {
TraitTyParamBound(ty) => print_type(s, ty),
RegionTyParamBound => word(s.s, ~"&static"),
RegionTyParamBound => word(s.s, ~"'static"),
}
}
}

View File

@ -37,10 +37,10 @@ fn to_foo_2<T:Copy>(t: T) -> @foo {
// Not OK---T may contain borrowed ptrs and it is going to escape
// as part of the returned foo value
struct F<T> { f: T }
@F {f:t} as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound
@F {f:t} as @foo //~ ERROR value may contain borrowed pointers; use `'static` bound
}
fn to_foo_3<T:Copy + &static>(t: T) -> @foo {
fn to_foo_3<T:Copy + 'static>(t: T) -> @foo {
// OK---T may escape as part of the returned foo value, but it is
// owned and hence does not contain borrowed ptrs
struct F<T> { f: T }

View File

@ -11,10 +11,10 @@
trait foo { fn foo(&self); }
fn to_foo<T:Copy + foo>(t: T) -> @foo {
@t as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound
@t as @foo //~ ERROR value may contain borrowed pointers; use `'static` bound
}
fn to_foo2<T:Copy + foo + &static>(t: T) -> @foo {
fn to_foo2<T:Copy + foo + 'static>(t: T) -> @foo {
@t as @foo
}

View File

@ -13,22 +13,22 @@ fn copy1<T:Copy>(t: T) -> @fn() -> T {
result
}
fn copy2<T:Copy + &static>(t: T) -> @fn() -> T {
fn copy2<T:Copy + 'static>(t: T) -> @fn() -> T {
let result: @fn() -> T = || t;
result
}
fn main() {
let x = &3;
copy2(&x); //~ ERROR does not fulfill `&static`
copy2(&x); //~ ERROR does not fulfill `'static`
copy2(@3);
copy2(@&x); //~ ERROR does not fulfill `&static`
copy2(@&x); //~ ERROR does not fulfill `'static`
let boxed: @fn() = || {};
copy2(boxed);
let owned: ~fn() = || {};
copy2(owned); //~ ERROR does not fulfill `Copy`
let borrowed: &fn() = || {};
copy2(borrowed); //~ ERROR does not fulfill `&static`
copy2(borrowed); //~ ERROR does not fulfill `'static`
}

View File

@ -1,4 +1,4 @@
fn f<T:&static>(_: T) {}
fn f<T:'static>(_: T) {}
fn main() {
let x = @3;

View File

@ -12,7 +12,7 @@ struct pair<A,B> {
a: A, b: B
}
fn f<A:Copy + &static>(a: A, b: u16) -> @fn() -> (A, u16) {
fn f<A:Copy + 'static>(a: A, b: u16) -> @fn() -> (A, u16) {
let result: @fn() -> (A, u16) = || (a, b);
result
}

View File

@ -16,7 +16,7 @@ struct Pair<A,B> {
a: A, b: B
}
fn f<A:Copy + &static>(a: A, b: u16) -> @fn() -> (A, u16) {
fn f<A:Copy + 'static>(a: A, b: u16) -> @fn() -> (A, u16) {
let result: @fn() -> (A, u16) = || (a, b);
result
}

View File

@ -10,11 +10,11 @@
// xfail-fast
fn fix_help<A:&static,B:Owned>(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B {
fn fix_help<A:'static,B:Owned>(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B {
return f(|a| fix_help(f, a), x);
}
fn fix<A:&static,B:Owned>(f: extern fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B {
fn fix<A:'static,B:Owned>(f: extern fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B {
return |a| fix_help(f, a);
}

View File

@ -11,7 +11,7 @@
trait hax { }
impl<A> hax for A { }
fn perform_hax<T:&static>(x: @T) -> @hax {
fn perform_hax<T:'static>(x: @T) -> @hax {
@x as @hax
}

View File

@ -11,7 +11,7 @@
trait hax { }
impl<A> hax for A { }
fn perform_hax<T:&static>(x: @T) -> @hax {
fn perform_hax<T:'static>(x: @T) -> @hax {
@x as @hax
}

View File

@ -59,7 +59,7 @@ fn square_from_char(c: char) -> square {
}
}
fn read_board_grid<rdr: &static + io::Reader>(+in: rdr) -> ~[~[square]] {
fn read_board_grid<rdr:'static + io::Reader>(+in: rdr) -> ~[~[square]] {
let in = @in as @io::Reader;
let mut grid = ~[];
for in.each_line |line| {