use std::fmt;
use std::rc::Rc;
+use std::borrow::Cow;
use serialize::{Encodable, Decodable, Encoder, Decoder};
// FIXME #6993: in librustc, uses of "ident" should be replaced
impl fmt::Debug for Stmt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "stmt({}: {})",
- ast_util::stmt_id(self),
+ ast_util::stmt_id(self)
+ .map_or(Cow::Borrowed("<macro>"),|id|Cow::Owned(id.to_string())),
pprust::stmt_to_string(self))
}
}
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,
}
}
}
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)
}