syntax: move MethMac to MacImplItem and combine {Provided,Required}Method into MethodTraitItem.
This commit is contained in:
parent
ce10fa8d12
commit
9da918548d
37 changed files with 466 additions and 551 deletions
|
|
@ -28,7 +28,6 @@ use ast::{Block, FnDecl, NodeId};
|
|||
use ast;
|
||||
use ast_map::{Node};
|
||||
use ast_map;
|
||||
use ast_util::PostExpansionMethod;
|
||||
use codemap::Span;
|
||||
use visit;
|
||||
|
||||
|
|
@ -65,7 +64,7 @@ impl MaybeFnLike for ast::Item {
|
|||
|
||||
impl MaybeFnLike for ast::TraitItem {
|
||||
fn is_fn_like(&self) -> bool {
|
||||
match self.node { ast::ProvidedMethod(_) => true, _ => false, }
|
||||
match self.node { ast::MethodTraitItem(_, Some(_)) => true, _ => false, }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,25 +155,25 @@ impl<'a> FnLikeNode<'a> {
|
|||
|
||||
pub fn body(self) -> &'a Block {
|
||||
self.handle(|i: ItemFnParts<'a>| &*i.body,
|
||||
|_, _, m: &'a ast::Method, _| m.pe_body(),
|
||||
|_, _, _: &'a ast::MethodSig, body: &'a ast::Block, _| body,
|
||||
|c: ClosureParts<'a>| c.body)
|
||||
}
|
||||
|
||||
pub fn decl(self) -> &'a FnDecl {
|
||||
self.handle(|i: ItemFnParts<'a>| &*i.decl,
|
||||
|_, _, m: &'a ast::Method, _| &m.pe_sig().decl,
|
||||
|_, _, sig: &'a ast::MethodSig, _, _| &sig.decl,
|
||||
|c: ClosureParts<'a>| c.decl)
|
||||
}
|
||||
|
||||
pub fn span(self) -> Span {
|
||||
self.handle(|i: ItemFnParts| i.span,
|
||||
|_, _, _: &'a ast::Method, span| span,
|
||||
|_, _, _: &'a ast::MethodSig, _, span| span,
|
||||
|c: ClosureParts| c.span)
|
||||
}
|
||||
|
||||
pub fn id(self) -> NodeId {
|
||||
self.handle(|i: ItemFnParts| i.id,
|
||||
|id, _, _: &'a ast::Method, _| id,
|
||||
|id, _, _: &'a ast::MethodSig, _, _| id,
|
||||
|c: ClosureParts| c.id)
|
||||
}
|
||||
|
||||
|
|
@ -185,15 +184,15 @@ impl<'a> FnLikeNode<'a> {
|
|||
let closure = |_: ClosureParts| {
|
||||
visit::FkFnBlock
|
||||
};
|
||||
let method = |_, ident, m: &'a ast::Method, _| {
|
||||
visit::FkMethod(ident, m)
|
||||
let method = |_, ident, sig: &'a ast::MethodSig, _, _| {
|
||||
visit::FkMethod(ident, sig)
|
||||
};
|
||||
self.handle(item, method, closure)
|
||||
}
|
||||
|
||||
fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
|
||||
I: FnOnce(ItemFnParts<'a>) -> A,
|
||||
M: FnOnce(NodeId, ast::Ident, &'a ast::Method, Span) -> A,
|
||||
M: FnOnce(NodeId, ast::Ident, &'a ast::MethodSig, &'a ast::Block, Span) -> A,
|
||||
C: FnOnce(ClosureParts<'a>) -> A,
|
||||
{
|
||||
match self.node {
|
||||
|
|
@ -206,13 +205,18 @@ impl<'a> FnLikeNode<'a> {
|
|||
_ => panic!("item FnLikeNode that is not fn-like"),
|
||||
},
|
||||
ast_map::NodeTraitItem(ti) => match ti.node {
|
||||
ast::ProvidedMethod(ref m) => method(ti.id, ti.ident, m, ti.span),
|
||||
ast::MethodTraitItem(ref sig, Some(ref body)) => {
|
||||
method(ti.id, ti.ident, sig, body, ti.span)
|
||||
}
|
||||
_ => panic!("trait method FnLikeNode that is not fn-like"),
|
||||
},
|
||||
ast_map::NodeImplItem(ii) => {
|
||||
match ii.node {
|
||||
ast::MethodImplItem(ref m) => method(ii.id, ii.ident, m, ii.span),
|
||||
ast::TypeImplItem(_) => {
|
||||
ast::MethodImplItem(ref sig, ref body) => {
|
||||
method(ii.id, ii.ident, sig, body, ii.span)
|
||||
}
|
||||
ast::TypeImplItem(_) |
|
||||
ast::MacImplItem(_) => {
|
||||
panic!("impl method FnLikeNode that is not fn-like")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -929,16 +929,10 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
|||
}
|
||||
Some(NodeImplItem(ii)) => {
|
||||
match ii.node {
|
||||
MethodImplItem(ref m) => {
|
||||
match *m {
|
||||
MethDecl(..) =>
|
||||
format!("method {} in {}{}",
|
||||
token::get_ident(ii.ident),
|
||||
map.path_to_string(id), id_str),
|
||||
MethMac(ref mac) =>
|
||||
format!("method macro {}{}",
|
||||
pprust::mac_to_string(mac), id_str)
|
||||
}
|
||||
MethodImplItem(..) => {
|
||||
format!("method {} in {}{}",
|
||||
token::get_ident(ii.ident),
|
||||
map.path_to_string(id), id_str)
|
||||
}
|
||||
TypeImplItem(_) => {
|
||||
format!("assoc type {} in {}{}",
|
||||
|
|
@ -946,13 +940,17 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
|||
map.path_to_string(id),
|
||||
id_str)
|
||||
}
|
||||
MacImplItem(ref mac) => {
|
||||
format!("method macro {}{}",
|
||||
pprust::mac_to_string(mac), id_str)
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(NodeTraitItem(ti)) => {
|
||||
let kind = match ti.node {
|
||||
RequiredMethod(_) => "required method",
|
||||
ProvidedMethod(_) => "provided method",
|
||||
MethodTraitItem(..) => "trait method",
|
||||
TypeTraitItem(..) => "assoc type",
|
||||
// ConstTraitItem(..) => "assoc constant"
|
||||
};
|
||||
|
||||
format!("{} {} in {}{}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue