diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-04-06 13:51:55 +0300 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2016-04-06 13:51:55 +0300 |
| commit | e8a8dfb056fb3654bacd6aaa6acbc4536358df23 (patch) | |
| tree | 3d379b80f98e27fd27d953276830278942f0eefc /src/librustc_driver | |
| parent | 20f0f3c1f131b54dcc6fdc7eeb1d04ea89f5f6fd (diff) | |
| download | rust-e8a8dfb056fb3654bacd6aaa6acbc4536358df23.tar.gz rust-e8a8dfb056fb3654bacd6aaa6acbc4536358df23.zip | |
rustc: retire hir::map's paths.
Diffstat (limited to 'src/librustc_driver')
| -rw-r--r-- | src/librustc_driver/pretty.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index cda5595c102..cde5ba19859 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -256,6 +256,15 @@ trait HirPrinterSupport<'ast>: pprust_hir::PpAnn { /// (Rust does not yet support upcasting from a trait object to /// an object for one of its super-traits.) fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn; + + /// Computes an user-readable representation of a path, if possible. + fn node_path(&self, id: ast::NodeId) -> Option<String> { + self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| { + path.data.into_iter().map(|elem| { + elem.data.to_string() + }).collect::<Vec<_>>().join("::") + }) + } } struct NoAnn<'ast> { @@ -452,6 +461,10 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> { fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn { self } + + fn node_path(&self, id: ast::NodeId) -> Option<String> { + Some(self.tcx.node_path_str(id)) + } } impl<'a, 'tcx> pprust_hir::PpAnn for TypedAnnotation<'a, 'tcx> { @@ -794,7 +807,7 @@ pub fn pretty_print_input(sess: Session, |annotation, (out,uii), _| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); - let ast_map = annotation.ast_map().expect("--pretty missing ast_map"); + let ast_map = annotation.ast_map().expect("--unpretty missing HIR map"); let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(), sess.diagnostic(), @@ -808,7 +821,9 @@ pub fn pretty_print_input(sess: Session, let node = ast_map.get(node_id); pp_state.print_node(&node)?; pp::space(&mut pp_state.s)?; - pp_state.synth_comment(ast_map.path_to_string(node_id))?; + let path = annotation.node_path(node_id) + .expect("--unpretty missing node paths"); + pp_state.synth_comment(path)?; pp::hardbreak(&mut pp_state.s)?; } pp::eof(&mut pp_state.s) |
