diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-01-10 11:16:54 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-01-10 11:16:54 -0800 |
| commit | 2a1b6c4de993c8db1bda35d58426d873e9e514c2 (patch) | |
| tree | a348bb8b51487c1504a9c923c2bf489e58047348 /src/libsyntax | |
| parent | 982830c836b8c2c9cb3fd311c826bf5775ad1232 (diff) | |
| download | rust-2a1b6c4de993c8db1bda35d58426d873e9e514c2.tar.gz rust-2a1b6c4de993c8db1bda35d58426d873e9e514c2.zip | |
librustc: Implement `&static` as the replacement for `Durable`. r=nmatsakis
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 7 |
7 files changed, 45 insertions, 23 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 072a7e94fe9..2cd873414c4 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -110,7 +110,10 @@ const crate_node_id: node_id = 0; // typeck::collect::compute_bounds matches these against // the "special" built-in traits (see middle::lang_items) and // detects Copy, Send, Owned, and Const. -enum ty_param_bound = @Ty; +enum ty_param_bound { + TraitTyParamBound(@Ty), + RegionTyParamBound +} #[auto_encode] #[auto_decode] diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 90df6fde8e3..2b3fefd6e51 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -245,7 +245,7 @@ priv impl ext_ctxt { path: @ast::path, bounds: @~[ast::ty_param_bound] ) -> ast::ty_param { - let bound = ast::ty_param_bound(@{ + let bound = ast::TraitTyParamBound(@{ id: self.next_id(), node: ast::ty_path(path, self.next_id()), span: span, @@ -397,7 +397,7 @@ fn mk_impl( let mut trait_tps = vec::append( ~[ty_param], do tps.map |tp| { - let t_bound = ast::ty_param_bound(@{ + let t_bound = ast::TraitTyParamBound(@{ id: cx.next_id(), node: ast::ty_path(path, cx.next_id()), span: span, diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs index 8e36dc01e2a..afce1edf158 100644 --- a/src/libsyntax/ext/deriving.rs +++ b/src/libsyntax/ext/deriving.rs @@ -13,13 +13,13 @@ use core::prelude::*; -use ast::{Ty, and, bind_by_ref, binop, deref, enum_def, enum_variant_kind}; -use ast::{expr, expr_match, ident, item, item_, item_struct, item_enum}; -use ast::{item_impl, m_imm, meta_item, method, named_field, or, pat}; -use ast::{pat_ident, pat_wild, public, pure_fn, re_anon, spanned, stmt}; -use ast::{struct_def, struct_variant_kind, sty_by_ref, sty_region}; -use ast::{tuple_variant_kind, ty_nil, ty_param, ty_param_bound, ty_path}; -use ast::{ty_rptr, unnamed_field, variant}; +use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def}; +use ast::{enum_variant_kind, expr, expr_match, ident, item, item_}; +use ast::{item_enum, item_impl, item_struct, m_imm, meta_item, method}; +use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn}; +use ast::{re_anon, spanned, stmt, struct_def, struct_variant_kind}; +use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, ty_param}; +use ast::{ty_param_bound, ty_path, ty_rptr, unnamed_field, variant}; use ext::base::ext_ctxt; use ext::build; use codemap::span; @@ -211,7 +211,7 @@ fn create_derived_impl(cx: ext_ctxt, let bound = build::mk_ty_path_global(cx, span, trait_path.map(|x| *x)); - let bounds = @~[ ty_param_bound(bound) ]; + let bounds = @~[ TraitTyParamBound(bound) ]; let impl_ty_param = build::mk_ty_param(cx, ty_param.ident, bounds); impl_ty_params.push(move impl_ty_param); } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 272ad3456e5..bca2336bc8c 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -141,7 +141,10 @@ fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl { } fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound { - ty_param_bound(fld.fold_ty(*tpb)) + match tpb { + TraitTyParamBound(ty) => TraitTyParamBound(fld.fold_ty(ty)), + RegionTyParamBound => RegionTyParamBound + } } fn fold_ty_param(tp: ty_param, fld: ast_fold) -> ty_param { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1a549fc93d5..6974ac508aa 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -10,7 +10,8 @@ use core::prelude::*; -use ast::{ProtoBox, ProtoUniq, provided, public, pure_fn, purity, re_static}; +use ast::{ProtoBox, ProtoUniq, RegionTyParamBound, TraitTyParamBound}; +use ast::{provided, public, pure_fn, purity, re_static}; use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_value, bind_by_move, bitand, bitor, bitxor, blk}; use ast::{blk_check_mode, box, by_copy, by_move, by_ref, by_val}; @@ -2401,8 +2402,16 @@ impl Parser { fn parse_optional_ty_param_bounds() -> @~[ty_param_bound] { let mut bounds = ~[]; if self.eat(token::COLON) { - while is_ident(self.token) { - if is_ident(self.token) { + loop { + if self.eat(token::BINOP(token::AND)) { + if self.eat_keyword(~"static") { + bounds.push(RegionTyParamBound); + } else { + self.span_err(copy self.span, + ~"`&static` is the only permissible \ + region bound here"); + } + } else if is_ident(self.token) { let maybe_bound = match self.token { token::IDENT(copy sid, _) => { match *self.id_to_str(sid) { @@ -2415,7 +2424,7 @@ impl Parser { ObsoleteLowerCaseKindBounds); // Bogus value, but doesn't matter, since // is an error - Some(ty_param_bound(self.mk_ty_path(sid))) + Some(TraitTyParamBound(self.mk_ty_path(sid))) } _ => None @@ -2430,11 +2439,12 @@ impl Parser { bounds.push(bound); } None => { - bounds.push(ty_param_bound(self.parse_ty(false))); + let ty = self.parse_ty(false); + bounds.push(TraitTyParamBound(ty)); } } } else { - bounds.push(ty_param_bound(self.parse_ty(false))); + break; } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 272c35152bb..f7117cc7043 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -10,7 +10,7 @@ use core::prelude::*; -use ast::{required, provided}; +use ast::{RegionTyParamBound, TraitTyParamBound, required, provided}; use ast; use ast_util; use ast_util::{operator_prec}; @@ -1791,9 +1791,12 @@ fn print_arg_mode(s: ps, m: ast::mode) { fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) { if bounds.is_not_empty() { word(s.s, ~":"); - for vec::each(*bounds) |bound| { + for vec::each(*bounds) |&bound| { nbsp(s); - print_type(s, **bound); + match bound { + TraitTyParamBound(ty) => print_type(s, ty), + RegionTyParamBound => word(s.s, ~"&static"), + } } } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 0da6396253e..25ea76d9b51 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -288,8 +288,11 @@ fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) { } fn visit_ty_param_bounds<E>(bounds: @~[ty_param_bound], e: E, v: vt<E>) { - for vec::each(*bounds) |bound| { - (v.visit_ty)(**bound, e, v) + for bounds.each |&bound| { + match bound { + TraitTyParamBound(ty) => (v.visit_ty)(ty, e, v), + RegionTyParamBound => () + } } } |
