]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_driver/pretty.rs
Simplify Cache wrapper to single type, impl Deref on it, fix all compilation errors...
[rust.git] / src / librustc_driver / pretty.rs
index 23253dc4dadec9733fa37f5fe2768ea9cfd40f43..11603f6d9c121c10cfe739747fe2d92cde08e64f 100644 (file)
@@ -5,7 +5,7 @@
 use rustc::hir::print as pprust_hir;
 use rustc::hir::def_id::LOCAL_CRATE;
 use rustc::session::Session;
-use rustc::session::config::{PpMode, PpSourceMode, UserIdentifiedItem, Input};
+use rustc::session::config::{PpMode, PpSourceMode, Input};
 use rustc::ty::{self, TyCtxt};
 use rustc::util::common::ErrorReported;
 use rustc_mir::util::{write_mir_pretty, write_mir_graphviz};
 use std::io::Write;
 use std::path::Path;
 
-pub use self::UserIdentifiedItem::*;
 pub use self::PpSourceMode::*;
 pub use self::PpMode::*;
 use crate::abort_on_err;
 
-use crate::source_name;
-
-
-
 // This slightly awkward construction is to allow for each PpMode to
 // choose whether it needs to do analyses (which can consume the
 // Session) and then pass through the session (now attached to the
@@ -391,7 +386,7 @@ fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
 }
 
 fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
-    let src_name = source_name(input);
+    let src_name = input.source_name();
     let src = String::clone(&sess.source_map()
         .get_source_file(&src_name)
         .unwrap()
@@ -448,14 +443,12 @@ pub fn print_after_hir_lowering<'tcx>(
     input: &Input,
     krate: &ast::Crate,
     ppm: PpMode,
-    opt_uii: Option<UserIdentifiedItem>,
     ofile: Option<&Path>,
 ) {
     if ppm.needs_analysis() {
         abort_on_err(print_with_analysis(
             tcx,
             ppm,
-            opt_uii,
             ofile
         ), tcx.sess);
         return;
@@ -465,8 +458,8 @@ pub fn print_after_hir_lowering<'tcx>(
 
     let mut out = String::new();
 
-    match (ppm, opt_uii) {
-            (PpmSource(s), _) => {
+    match ppm {
+            PpmSource(s) => {
                 // Silently ignores an identified node.
                 let out = &mut out;
                 let src = src.clone();
@@ -483,7 +476,7 @@ pub fn print_after_hir_lowering<'tcx>(
                 })
             }
 
-            (PpmHir(s), None) => {
+            PpmHir(s) => {
                 let out = &mut out;
                 let src = src.clone();
                 call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
@@ -498,7 +491,7 @@ pub fn print_after_hir_lowering<'tcx>(
                 })
             }
 
-            (PpmHirTree(s), None) => {
+            PpmHirTree(s) => {
                 let out = &mut out;
                 call_with_pp_support_hir(&s, tcx, move |_annotation, krate| {
                     debug!("pretty printing source code {:?}", s);
@@ -506,44 +499,6 @@ pub fn print_after_hir_lowering<'tcx>(
                 });
             }
 
-            (PpmHir(s), Some(uii)) => {
-                let out = &mut out;
-                let src = src.clone();
-                call_with_pp_support_hir(&s, tcx, move |annotation, _| {
-                    debug!("pretty printing source code {:?}", s);
-                    let sess = annotation.sess();
-                    let hir_map = annotation.hir_map().expect("-Z unpretty missing HIR map");
-                    let mut pp_state = pprust_hir::State::new_from_input(sess.source_map(),
-                                                                         &sess.parse_sess,
-                                                                         src_name,
-                                                                         src,
-                                                                         annotation.pp_ann());
-                    for node_id in uii.all_matching_node_ids(hir_map) {
-                        let hir_id = tcx.hir().node_to_hir_id(node_id);
-                        let node = hir_map.get(hir_id);
-                        pp_state.print_node(node);
-                        pp_state.s.space();
-                        let path = annotation.node_path(hir_id)
-                            .expect("-Z unpretty missing node paths");
-                        pp_state.synth_comment(path);
-                        pp_state.s.hardbreak();
-                    }
-                    *out = pp_state.s.eof();
-                })
-            }
-
-            (PpmHirTree(s), Some(uii)) => {
-                let out = &mut out;
-                call_with_pp_support_hir(&s, tcx, move |_annotation, _krate| {
-                    debug!("pretty printing source code {:?}", s);
-                    for node_id in uii.all_matching_node_ids(tcx.hir()) {
-                        let hir_id = tcx.hir().node_to_hir_id(node_id);
-                        let node = tcx.hir().get(hir_id);
-                        out.push_str(&format!("{:#?}", node));
-                    }
-                })
-            }
-
             _ => unreachable!(),
         }
 
@@ -557,27 +512,17 @@ pub fn print_after_hir_lowering<'tcx>(
 fn print_with_analysis(
     tcx: TyCtxt<'_>,
     ppm: PpMode,
-    uii: Option<UserIdentifiedItem>,
     ofile: Option<&Path>,
 ) -> Result<(), ErrorReported> {
-    let nodeid = if let Some(uii) = uii {
-        debug!("pretty printing for {:?}", uii);
-        Some(uii.to_one_node_id("-Z unpretty", tcx.sess, tcx.hir()))
-    } else {
-        debug!("pretty printing for whole crate");
-        None
-    };
-
     let mut out = Vec::new();
 
     tcx.analysis(LOCAL_CRATE)?;
 
     match ppm {
         PpmMir | PpmMirCFG => {
-            let def_id = nodeid.map(|nid| tcx.hir().local_def_id_from_node_id(nid));
             match ppm {
-                PpmMir => write_mir_pretty(tcx, def_id, &mut out),
-                PpmMirCFG => write_mir_graphviz(tcx, def_id, &mut out),
+                PpmMir => write_mir_pretty(tcx, None, &mut out),
+                PpmMirCFG => write_mir_graphviz(tcx, None, &mut out),
                 _ => unreachable!(),
             }
         }