X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibsyntax%2Fast_util.rs;h=c52c5984858a91cc6b3ce1199cdc0f1d53dbc8c9;hb=beda1f88a7d87cf994fe8e3a5b2fe126e31fcae9;hp=d024ff117f579d97cbffd8bd11a337b39b92b0b8;hpb=6f1014f3510f3c5cc2b524aa4cb18bf91c3fd50f;p=rust.git diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index d024ff117f5..c52c5984858 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -28,12 +28,12 @@ pub fn path_name_i(idents: &[Ident]) -> String { idents.iter().map(|i| i.to_string()).collect::>().join("::") } -pub fn stmt_id(s: &Stmt) -> NodeId { +pub fn stmt_id(s: &Stmt) -> Option { 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, } } @@ -101,10 +101,9 @@ pub fn is_by_value_unop(u: UnOp) -> bool { pub fn unop_to_string(op: UnOp) -> &'static str { match op { - UnUniq => "box() ", - UnDeref => "*", - UnNot => "!", - UnNeg => "-", + UnDeref => "*", + UnNot => "!", + UnNeg => "-", } } @@ -361,11 +360,6 @@ fn visit_item(&mut self, item: &Item) { } } } - ItemEnum(ref enum_definition, _) => { - for variant in &enum_definition.variants { - self.operation.visit_id(variant.node.id) - } - } _ => {} } @@ -385,7 +379,8 @@ fn visit_block(&mut self, block: &Block) { } 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) } @@ -461,9 +456,9 @@ fn visit_struct_def(&mut self, 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); } @@ -477,12 +472,12 @@ fn visit_impl_item(&mut self, ii: &ast::ImplItem) { 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) { @@ -529,12 +524,6 @@ pub fn compute_id_range_for_fn_body(fk: FnKind, id_visitor.operation.result } -/// 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) -> bool { @@ -577,21 +566,21 @@ mod tests { 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::>(), - &[Ident{name:Name(3),ctxt:104}, Ident{name:Name(78),ctxt:182}] - .iter().map(ident_to_segment).collect::>())); + &[Ident::new(Name(3),SyntaxContext(4)), Ident::new(Name(78),SyntaxContext(82))] + .iter().cloned().map(ident_to_segment).collect::>(), + &[Ident::new(Name(3),SyntaxContext(104)), Ident::new(Name(78),SyntaxContext(182))] + .iter().cloned().map(ident_to_segment).collect::>())); assert!(!segments_name_eq( - &[Ident{name:Name(3),ctxt:4}, Ident{name:Name(78),ctxt:82}] - .iter().map(ident_to_segment).collect::>(), - &[Ident{name:Name(3),ctxt:104}, Ident{name:Name(77),ctxt:182}] - .iter().map(ident_to_segment).collect::>())); + &[Ident::new(Name(3),SyntaxContext(4)), Ident::new(Name(78),SyntaxContext(82))] + .iter().cloned().map(ident_to_segment).collect::>(), + &[Ident::new(Name(3),SyntaxContext(104)), Ident::new(Name(77),SyntaxContext(182))] + .iter().cloned().map(ident_to_segment).collect::>())); } }