diff options
| author | bors <bors@rust-lang.org> | 2013-04-05 18:00:52 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-04-05 18:00:52 -0700 |
| commit | 08e2cf846aebf5a9f5e53881814976a3beee89a7 (patch) | |
| tree | ed81332bccf792d086d46c604b724a444f8656d0 /src/libsyntax | |
| parent | babe50633349cd29f0a0757079e0e13bdc0310fa (diff) | |
| parent | 13801f60b26009991cd6880b6b40fae9265a8280 (diff) | |
| download | rust-08e2cf846aebf5a9f5e53881814976a3beee89a7.tar.gz rust-08e2cf846aebf5a9f5e53881814976a3beee89a7.zip | |
auto merge of #5676 : nikomatsakis/rust/issue-4183-trait_ref, r=nikomatsakis
These are a number of incremental steps towards #4183 and #4646.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/mod.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 25 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 14 |
9 files changed, 57 insertions, 39 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2e7ae4c537a..ec77b54a853 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -144,7 +144,7 @@ pub static crate_node_id: node_id = 0; // the "special" built-in traits (see middle::lang_items) and // detects Copy, Send, Owned, and Const. pub enum TyParamBound { - TraitTyParamBound(@Ty), + TraitTyParamBound(@trait_ref), RegionTyParamBound } @@ -194,6 +194,7 @@ pub enum def { def_local(node_id, bool /* is_mutbl */), def_variant(def_id /* enum */, def_id /* variant */), def_ty(def_id), + def_trait(def_id), def_prim_ty(prim_ty), def_ty_param(def_id, uint), def_binding(node_id, binding_mode), @@ -1185,6 +1186,15 @@ pub struct trait_ref { #[deriving(Eq)] pub enum visibility { public, private, inherited } +impl visibility { + fn inherit_from(&self, parent_visibility: visibility) -> visibility { + match self { + &inherited => parent_visibility, + &public | &private => *self + } + } +} + #[auto_encode] #[auto_decode] #[deriving(Eq)] diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 208ed1e35fe..c7227fa1768 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -61,7 +61,7 @@ pub fn def_id_of_def(d: def) -> def_id { def_fn(id, _) | def_static_method(id, _, _) | def_mod(id) | def_foreign_mod(id) | def_const(id) | def_variant(_, id) | def_ty(id) | def_ty_param(id, _) | - def_use(id) | def_struct(id) => { + def_use(id) | def_struct(id) | def_trait(id) => { id } def_arg(id, _, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id) diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index d25792355a7..97bc89248ac 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -222,15 +222,14 @@ pub fn expand_auto_decode( priv impl @ext_ctxt { fn bind_path( &self, - span: span, + _span: span, ident: ast::ident, path: @ast::path, bounds: @OptVec<ast::TyParamBound> ) -> ast::TyParam { - let bound = ast::TraitTyParamBound(@ast::Ty { - id: self.next_id(), - node: ast::ty_path(path, self.next_id()), - span: span, + let bound = ast::TraitTyParamBound(@ast::trait_ref { + ref_id: self.next_id(), + path: path }); ast::TyParam { @@ -466,10 +465,9 @@ fn mk_impl( // All the type parameters need to bound to the trait. let mut impl_tps = opt_vec::with(ty_param); for generics.ty_params.each |tp| { - let t_bound = ast::TraitTyParamBound(@ast::Ty { - id: cx.next_id(), - node: ast::ty_path(path, cx.next_id()), - span: span, + let t_bound = ast::TraitTyParamBound(@ast::trait_ref { + path: path, + ref_id: cx.next_id(), }); impl_tps.push(ast::TyParam { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 9499f95f0e7..43f0c9edcb9 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -337,6 +337,17 @@ pub fn mk_ty_path_global(cx: @ext_ctxt, let ty = @ast::Ty { id: cx.next_id(), node: ty, span: span }; ty } +pub fn mk_trait_ref_global(cx: @ext_ctxt, + span: span, + +idents: ~[ ast::ident ]) + -> @ast::trait_ref +{ + let path = build::mk_raw_path_global(span, idents); + @ast::trait_ref { + path: path, + ref_id: cx.next_id() + } +} pub fn mk_simple_ty_path(cx: @ext_ctxt, span: span, ident: ast::ident) diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 18ebceaeb43..ccd9a33757d 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -177,9 +177,9 @@ pub fn create_derived_impl(cx: @ext_ctxt, // Create the type parameters. let impl_ty_params = generics.ty_params.map(|ty_param| { - let bound = build::mk_ty_path_global(cx, - span, - trait_path.map(|x| *x)); + let bound = build::mk_trait_ref_global(cx, + span, + trait_path.map(|x| *x)); let bounds = @opt_vec::with(TraitTyParamBound(bound)); build::mk_ty_param(cx, ty_param.ident, bounds) }); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 0a473b1cebe..5aa51c262e1 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -134,7 +134,7 @@ pub fn fold_fn_decl(decl: &ast::fn_decl, fld: @ast_fold) -> ast::fn_decl { fn fold_ty_param_bound(tpb: &TyParamBound, fld: @ast_fold) -> TyParamBound { match *tpb { - TraitTyParamBound(ty) => TraitTyParamBound(fld.fold_ty(ty)), + TraitTyParamBound(ty) => TraitTyParamBound(fold_trait_ref(ty, fld)), RegionTyParamBound => RegionTyParamBound } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1d780c9b806..3a3597828cd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2750,8 +2750,8 @@ pub impl Parser { self.bump(); } token::MOD_SEP | token::IDENT(*) => { - let maybe_bound = match *self.token { - token::MOD_SEP => None, + let obsolete_bound = match *self.token { + token::MOD_SEP => false, token::IDENT(copy sid, _) => { match *self.id_to_str(sid) { ~"send" | @@ -2761,27 +2761,18 @@ pub impl Parser { self.obsolete( *self.span, ObsoleteLowerCaseKindBounds); - - // Bogus value, but doesn't matter, since - // is an error - Some(TraitTyParamBound( - self.mk_ty_path(sid))) + self.bump(); + true } - _ => None + _ => false } } _ => fail!() }; - match maybe_bound { - Some(bound) => { - self.bump(); - result.push(bound); - } - None => { - let ty = self.parse_ty(true); - result.push(TraitTyParamBound(ty)); - } + if !obsolete_bound { + let tref = self.parse_trait_ref(); + result.push(TraitTyParamBound(tref)); } } _ => break, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 0c79cbca039..20fc99baf21 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -562,7 +562,7 @@ pub fn print_item(s: @ps, &&item: @ast::item) { match opt_trait { Some(t) => { - print_path(s, t.path, false); + print_trait_ref(s, t); space(s.s); word_space(s, ~"for"); } @@ -619,6 +619,10 @@ pub fn print_item(s: @ps, &&item: @ast::item) { (s.ann.post)(ann_node); } +fn print_trait_ref(s: @ps, t: &ast::trait_ref) { + print_path(s, t.path, false); +} + pub fn print_enum_def(s: @ps, enum_definition: ast::enum_def, generics: &ast::Generics, ident: ast::ident, span: codemap::span, visibility: ast::visibility) { @@ -1744,7 +1748,7 @@ pub fn print_bounds(s: @ps, bounds: @OptVec<ast::TyParamBound>) { } match *bound { - TraitTyParamBound(ty) => print_type(s, ty), + TraitTyParamBound(tref) => print_trait_ref(s, tref), RegionTyParamBound => word(s.s, ~"'static"), } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index a994f2b5b22..b20c5eeee1f 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -147,6 +147,10 @@ pub fn visit_local<E>(loc: @local, e: E, v: vt<E>) { } } +fn visit_trait_ref<E>(tref: @ast::trait_ref, e: E, v: vt<E>) { + visit_path(tref.path, e, v); +} + pub fn visit_item<E>(i: @item, e: E, v: vt<E>) { match i.node { item_const(t, ex) => { @@ -189,9 +193,9 @@ pub fn visit_item<E>(i: @item, e: E, v: vt<E>) { } item_impl(ref tps, ref traits, ty, ref methods) => { (v.visit_generics)(tps, e, v); - for traits.each |p| { - visit_path(p.path, e, v); - } + for traits.each |&p| { + visit_trait_ref(p, e, v); + } (v.visit_ty)(ty, e, v); for methods.each |m| { visit_method_helper(*m, e, v) @@ -327,8 +331,8 @@ pub fn visit_ty_param_bounds<E>(bounds: @OptVec<TyParamBound>, e: E, v: vt<E>) { for bounds.each |bound| { match *bound { - TraitTyParamBound(ty) => (v.visit_ty)(ty, e, v), - RegionTyParamBound => () + TraitTyParamBound(ty) => visit_trait_ref(ty, e, v), + RegionTyParamBound => {} } } } |
