]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/ast.rs
Change syntax::ast_util::stmt_id to not panic on macros
[rust.git] / src / libsyntax / ast.rs
index 5b04fc0e6977b3ece9c9f1d26f31702b70ca088b..cdddaaffc357dfb66208018b58d80505a151de42 100644 (file)
@@ -65,6 +65,7 @@
 
 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
@@ -685,7 +686,8 @@ pub enum UnOp {
 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))
     }
 }