idents.iter().map(|i| i.to_string()).collect::<Vec<String>>().join("::")
}
-pub fn stmt_id(s: &Stmt) -> NodeId {
+pub fn stmt_id(s: &Stmt) -> Option<NodeId> {
match s.node {
- StmtDecl(_, id) => id,
- StmtExpr(_, id) => id,
- StmtSemi(_, id) => id,
- StmtMac(..) => panic!("attempted to analyze unexpanded stmt")
+ StmtDecl(_, id) => Some(id),
+ StmtExpr(_, id) => Some(id),
+ StmtSemi(_, id) => Some(id),
+ StmtMac(..) => None,
}
}
pub fn unop_to_string(op: UnOp) -> &'static str {
match op {
- UnUniq => "box() ",
- UnDeref => "*",
- UnNot => "!",
- UnNeg => "-",
+ UnDeref => "*",
+ UnNot => "!",
+ UnNeg => "-",
}
}
})
}
-pub fn name_to_dummy_lifetime(name: Name) -> Lifetime {
- Lifetime { id: DUMMY_NODE_ID,
- span: codemap::DUMMY_SP,
- name: name }
-}
-
/// Generate a "pretty" name for an `impl` from its type and trait.
/// This is designed so that symbols of `impl`'d methods give some
/// hint of where they came from, (previously they would all just be
}
}
}
- ItemEnum(ref enum_definition, _) => {
- for variant in &enum_definition.variants {
- self.operation.visit_id(variant.node.id)
- }
- }
_ => {}
}
}
fn visit_stmt(&mut self, statement: &Stmt) {
- self.operation.visit_id(ast_util::stmt_id(statement));
+ self.operation
+ .visit_id(ast_util::stmt_id(statement).expect("attempted to visit unexpanded stmt"));
visit::walk_stmt(self, statement)
}
struct_def: &StructDef,
_: ast::Ident,
_: &ast::Generics,
- id: NodeId) {
- self.operation.visit_id(id);
- struct_def.ctor_id.map(|ctor_id| self.operation.visit_id(ctor_id));
+ _: NodeId,
+ _: Span) {
+ self.operation.visit_id(struct_def.id);
visit::walk_struct_def(self, struct_def);
}
visit::walk_impl_item(self, ii);
}
- fn visit_lifetime_ref(&mut self, lifetime: &Lifetime) {
+ fn visit_lifetime(&mut self, lifetime: &Lifetime) {
self.operation.visit_id(lifetime.id);
}
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
- self.visit_lifetime_ref(&def.lifetime);
+ self.visit_lifetime(&def.lifetime);
}
fn visit_trait_ref(&mut self, trait_ref: &TraitRef) {
}
pub struct IdRangeComputingVisitor {
- result: IdRange,
+ pub result: IdRange,
}
impl IdRangeComputingVisitor {
id_visitor.operation.result
}
-pub fn walk_pat<F>(pat: &Pat, mut it: F) -> bool where F: FnMut(&Pat) -> bool {
- // FIXME(#19596) this is a workaround, but there should be a better way
- fn walk_pat_<G>(pat: &Pat, it: &mut G) -> bool where G: FnMut(&Pat) -> bool {
- if !(*it)(pat) {
- return false;
- }
-
- match pat.node {
- PatIdent(_, _, Some(ref p)) => walk_pat_(&**p, it),
- PatStruct(_, ref fields, _) => {
- fields.iter().all(|field| walk_pat_(&*field.node.pat, it))
- }
- PatEnum(_, Some(ref s)) | PatTup(ref s) => {
- s.iter().all(|p| walk_pat_(&**p, it))
- }
- PatBox(ref s) | PatRegion(ref s, _) => {
- walk_pat_(&**s, it)
- }
- PatVec(ref before, ref slice, ref after) => {
- before.iter().all(|p| walk_pat_(&**p, it)) &&
- slice.iter().all(|p| walk_pat_(&**p, it)) &&
- after.iter().all(|p| walk_pat_(&**p, it))
- }
- PatMac(_) => panic!("attempted to analyze unexpanded pattern"),
- PatWild(_) | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |
- PatEnum(_, _) | PatQPath(_, _) => {
- true
- }
- }
- }
-
- walk_pat_(pat, &mut it)
-}
-
-/// Returns true if the given struct def is tuple-like; i.e. that its fields
-/// are unnamed.
-pub fn struct_def_is_tuple_like(struct_def: &ast::StructDef) -> bool {
- struct_def.ctor_id.is_some()
-}
-
/// Returns true if the given pattern consists solely of an identifier
/// and false otherwise.
pub fn pat_is_ident(pat: P<ast::Pat>) -> bool {
use ast::*;
use super::*;
- fn ident_to_segment(id : &Ident) -> PathSegment {
- PathSegment {identifier: id.clone(),
+ fn ident_to_segment(id: Ident) -> PathSegment {
+ PathSegment {identifier: id,
parameters: PathParameters::none()}
}
#[test] fn idents_name_eq_test() {
assert!(segments_name_eq(
- &[Ident{name:Name(3),ctxt:4}, Ident{name:Name(78),ctxt:82}]
- .iter().map(ident_to_segment).collect::<Vec<PathSegment>>(),
- &[Ident{name:Name(3),ctxt:104}, Ident{name:Name(78),ctxt:182}]
- .iter().map(ident_to_segment).collect::<Vec<PathSegment>>()));
+ &[Ident::new(Name(3),SyntaxContext(4)), Ident::new(Name(78),SyntaxContext(82))]
+ .iter().cloned().map(ident_to_segment).collect::<Vec<PathSegment>>(),
+ &[Ident::new(Name(3),SyntaxContext(104)), Ident::new(Name(78),SyntaxContext(182))]
+ .iter().cloned().map(ident_to_segment).collect::<Vec<PathSegment>>()));
assert!(!segments_name_eq(
- &[Ident{name:Name(3),ctxt:4}, Ident{name:Name(78),ctxt:82}]
- .iter().map(ident_to_segment).collect::<Vec<PathSegment>>(),
- &[Ident{name:Name(3),ctxt:104}, Ident{name:Name(77),ctxt:182}]
- .iter().map(ident_to_segment).collect::<Vec<PathSegment>>()));
+ &[Ident::new(Name(3),SyntaxContext(4)), Ident::new(Name(78),SyntaxContext(82))]
+ .iter().cloned().map(ident_to_segment).collect::<Vec<PathSegment>>(),
+ &[Ident::new(Name(3),SyntaxContext(104)), Ident::new(Name(77),SyntaxContext(182))]
+ .iter().cloned().map(ident_to_segment).collect::<Vec<PathSegment>>()));
}
}