Skip to content

Commit

Permalink
auto merge of rust-lang#5483 : pcwalton/rust/static-syntax, r=graydon
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Mar 22, 2013
2 parents f011f92 + 94327d0 commit b6f9aa1
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
77 changes: 40 additions & 37 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// Bogus value, but doesn't matter, since
// is an error
Some(TraitTyParamBound(
self.mk_ty_path(sid)))
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)))
}
_ => None
}
_ => None
}
}
_ => fail!()
};
_ => fail!()
};

match maybe_bound {
Some(bound) => {
self.bump();
result.push(bound);
}
None => {
let ty = self.parse_ty(false);
result.push(TraitTyParamBound(ty));
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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/kindck-owned-trait-scoped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/kindck-owned-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/kindck-owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/static-region-bound.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn f<T:&static>(_: T) {}
fn f<T:'static>(_: T) {}

fn main() {
let x = @3;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/alignment-gep-tup-like-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/close-over-big-then-small-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/fixed-point-bind-unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-2734.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-2735.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-2904.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down

0 comments on commit b6f9aa1

Please sign in to comment.