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 => { ty::bound_durable => {
if !kind.is_durable(cx.tcx) { 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 { match ty::get(ty).sty {
ty::ty_param(*) => { ty::ty_param(*) => {
tcx.sess.span_err(sp, ~"value may contain borrowed \ 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 \ 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 { pub fn param_bound_to_str(cx: ctxt, pb: &param_bound) -> ~str {
match *pb { match *pb {
bound_copy => ~"copy", bound_copy => ~"copy",
bound_durable => ~"&static", bound_durable => ~"'static",
bound_owned => ~"owned", bound_owned => ~"owned",
bound_const => ~"const", bound_const => ~"const",
bound_trait(t) => ::util::ppaux::ty_to_str(cx, t) 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; let mut result = opt_vec::Empty;
loop { loop {
if self.eat(&token::BINOP(token::AND)) { match *self.token {
if self.eat_keyword(&~"static") { token::LIFETIME(lifetime) => {
result.push(RegionTyParamBound); if str::eq_slice(*self.id_to_str(lifetime), "static") {
} else { result.push(RegionTyParamBound);
self.span_err(*self.span, } else {
~"`&static` is the only permissible \ self.span_err(*self.span,
region bound here"); ~"`'static` is the only permissible \
region bound here");
}
self.bump();
} }
} else if is_ident(&*self.token) { token::IDENT(*) => {
let maybe_bound = match *self.token { let maybe_bound = match *self.token {
token::IDENT(copy sid, _) => { token::IDENT(copy sid, _) => {
match *self.id_to_str(sid) { match *self.id_to_str(sid) {
~"send" | ~"send" |
~"copy" | ~"copy" |
~"const" | ~"const" |
~"owned" => { ~"owned" => {
self.obsolete( self.obsolete(
*self.span, *self.span,
ObsoleteLowerCaseKindBounds); ObsoleteLowerCaseKindBounds);
// Bogus value, but doesn't matter, since // Bogus value, but doesn't matter, since
// is an error // is an error
Some(TraitTyParamBound( Some(TraitTyParamBound(
self.mk_ty_path(sid))) 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)) { 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 { match *bound {
TraitTyParamBound(ty) => print_type(s, ty), 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 // Not OK---T may contain borrowed ptrs and it is going to escape
// as part of the returned foo value // as part of the returned foo value
struct F<T> { f: T } 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 // OK---T may escape as part of the returned foo value, but it is
// owned and hence does not contain borrowed ptrs // owned and hence does not contain borrowed ptrs
struct F<T> { f: T } struct F<T> { f: T }

View File

@ -11,10 +11,10 @@
trait foo { fn foo(&self); } trait foo { fn foo(&self); }
fn to_foo<T:Copy + foo>(t: T) -> @foo { 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 @t as @foo
} }

View File

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

View File

@ -12,7 +12,7 @@ struct pair<A,B> {
a: A, b: 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); let result: @fn() -> (A, u16) = || (a, b);
result result
} }

View File

@ -16,7 +16,7 @@ struct Pair<A,B> {
a: A, b: 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); let result: @fn() -> (A, u16) = || (a, b);
result result
} }

View File

@ -10,11 +10,11 @@
// xfail-fast // 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); 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); return |a| fix_help(f, a);
} }

View File

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

View File

@ -11,7 +11,7 @@
trait hax { } trait hax { }
impl<A> hax for A { } impl<A> hax for A { }
fn perform_hax<T:&static>(x: @T) -> @hax { fn perform_hax<T:'static>(x: @T) -> @hax {
@x as @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 in = @in as @io::Reader;
let mut grid = ~[]; let mut grid = ~[];
for in.each_line |line| { for in.each_line |line| {