diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-10-22 16:05:30 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-10-22 16:58:08 -0400 |
| commit | e5bc5c7aa06d876dc3135af1266c05850951337f (patch) | |
| tree | 4a940991a4b871b7244650e55f4088da9d0600a3 | |
| parent | 8fa5f09a8ff555fe5ff436e715869ba6139f50ed (diff) | |
| download | rust-e5bc5c7aa06d876dc3135af1266c05850951337f.tar.gz rust-e5bc5c7aa06d876dc3135af1266c05850951337f.zip | |
improve Scope to print node-ids etc
| -rw-r--r-- | src/librustc/middle/region.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index bdf01f941c4..1027bbf6703 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); |
