about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-10-22 16:05:30 -0400
committerBrian Anderson <banderson@mozilla.com>2015-10-23 18:29:56 -0700
commit99a8fc1d9c5ad0edd907e0ae798c6ef544e79cff (patch)
tree559e17bed00454968fb30fac4b19af6a1c14179c
parent3cab20c7c8c3395b3e996ed0fe66b3aeca438809 (diff)
downloadrust-99a8fc1d9c5ad0edd907e0ae798c6ef544e79cff.tar.gz
rust-99a8fc1d9c5ad0edd907e0ae798c6ef544e79cff.zip
improve Scope to print node-ids etc
-rw-r--r--src/librustc/middle/region.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs
index f08cbb41438..af6211665f1 100644
--- a/src/librustc/middle/region.rs
+++ b/src/librustc/middle/region.rs
@@ -24,6 +24,7 @@ use middle::ty::{self, Ty};
 
 use std::cell::RefCell;
 use std::collections::hash_map::Entry;
+use std::fmt;
 use std::mem;
 use syntax::codemap::{self, Span};
 use syntax::ast::{self, NodeId};
@@ -34,9 +35,25 @@ use rustc_front::hir::{Block, Item, FnDecl, Arm, Pat, Stmt, Expr, Local};
 use rustc_front::util::stmt_id;
 
 #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
-           RustcDecodable, Debug, Copy)]
+           RustcDecodable, Copy)]
 pub struct CodeExtent(u32);
 
+impl fmt::Debug for CodeExtent {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        try!(write!(f, "CodeExtent({:?}", self.0));
+
+        try!(ty::tls::with_opt(|opt_tcx| {
+            if let Some(tcx) = opt_tcx {
+                let data = tcx.region_maps.code_extents.borrow()[self.0 as usize];
+                try!(write!(f, "/{:?}", data));
+            }
+            Ok(())
+        }));
+
+        write!(f, ")")
+    }
+}
+
 /// The root of everything. I should be using NonZero or profiling
 /// instead of this (probably).
 pub const ROOT_CODE_EXTENT : CodeExtent = CodeExtent(0);