]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_driver/pretty.rs
Move the `krate` method to Hir and remove the Krate dep node
[rust.git] / src / librustc_driver / pretty.rs
index 8804a05b596ee1fa421ac6f6aaa97ff5614f05c7..d4f014904994102a7d30f06754104628b6fe08c9 100644 (file)
@@ -5,14 +5,13 @@
 use rustc::session::Session;
 use rustc::ty::{self, TyCtxt};
 use rustc::util::common::ErrorReported;
+use rustc_ast_pretty::pprust;
 use rustc_hir as hir;
 use rustc_hir::def_id::LOCAL_CRATE;
 use rustc_hir::print as pprust_hir;
 use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
-
 use rustc_span::FileName;
 use syntax::ast;
-use syntax::print::pprust;
 
 use std::cell::Cell;
 use std::fs::File;
@@ -70,19 +69,19 @@ fn call_with_pp_support_hir<A, F>(ppmode: &PpSourceMode, tcx: TyCtxt<'_>, f: F)
     match *ppmode {
         PpmNormal => {
             let annotation = NoAnn { sess: tcx.sess, tcx: Some(tcx) };
-            f(&annotation, tcx.hir().forest.krate())
+            f(&annotation, tcx.hir().krate())
         }
 
         PpmIdentified => {
             let annotation = IdentifiedAnnotation { sess: tcx.sess, tcx: Some(tcx) };
-            f(&annotation, tcx.hir().forest.krate())
+            f(&annotation, tcx.hir().krate())
         }
         PpmTyped => {
             abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);
 
             let empty_tables = ty::TypeckTables::empty(None);
             let annotation = TypedAnnotation { tcx, tables: Cell::new(&empty_tables) };
-            tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().forest.krate()))
+            tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
         }
         _ => panic!("Should use call_with_pp_support"),
     }
@@ -144,7 +143,7 @@ fn sess(&self) -> &Session {
     }
 
     fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> {
-        self.tcx.map(|tcx| tcx.hir())
+        self.tcx.map(|tcx| *tcx.hir())
     }
 
     fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
@@ -156,7 +155,7 @@ impl<'hir> pprust::PpAnn for NoAnn<'hir> {}
 impl<'hir> pprust_hir::PpAnn for NoAnn<'hir> {
     fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
         if let Some(tcx) = self.tcx {
-            pprust_hir::PpAnn::nested(tcx.hir(), state, nested)
+            pprust_hir::PpAnn::nested(*tcx.hir(), state, nested)
         }
     }
 }
@@ -218,7 +217,7 @@ fn sess(&self) -> &Session {
     }
 
     fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> {
-        self.tcx.map(|tcx| tcx.hir())
+        self.tcx.map(|tcx| *tcx.hir())
     }
 
     fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
@@ -229,7 +228,7 @@ fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
 impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
     fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
         if let Some(ref tcx) = self.tcx {
-            pprust_hir::PpAnn::nested(tcx.hir(), state, nested)
+            pprust_hir::PpAnn::nested(*tcx.hir(), state, nested)
         }
     }
     fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
@@ -335,7 +334,7 @@ fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested)
         if let pprust_hir::Nested::Body(id) = nested {
             self.tables.set(self.tcx.body_tables(id));
         }
-        pprust_hir::PpAnn::nested(self.tcx.hir(), state, nested);
+        pprust_hir::PpAnn::nested(*self.tcx.hir(), state, nested);
         self.tables.set(old_tables);
     }
     fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
@@ -392,14 +391,16 @@ pub fn print_after_parsing(
         call_with_pp_support(&s, sess, None, move |annotation| {
             debug!("pretty printing source code {:?}", s);
             let sess = annotation.sess();
+            let parse = &sess.parse_sess;
             *out = pprust::print_crate(
                 sess.source_map(),
-                &sess.parse_sess,
                 krate,
                 src_name,
                 src,
                 annotation.pp_ann(),
                 false,
+                parse.edition,
+                parse.injected_crate_name.try_get().is_some(),
             )
         })
     } else {
@@ -429,36 +430,30 @@ pub fn print_after_hir_lowering<'tcx>(
         PpmSource(s) => {
             // Silently ignores an identified node.
             let out = &mut out;
-            let src = src.clone();
             call_with_pp_support(&s, tcx.sess, Some(tcx), move |annotation| {
                 debug!("pretty printing source code {:?}", s);
                 let sess = annotation.sess();
+                let parse = &sess.parse_sess;
                 *out = pprust::print_crate(
                     sess.source_map(),
-                    &sess.parse_sess,
                     krate,
                     src_name,
                     src,
                     annotation.pp_ann(),
                     true,
+                    parse.edition,
+                    parse.injected_crate_name.try_get().is_some(),
                 )
             })
         }
 
         PpmHir(s) => {
             let out = &mut out;
-            let src = src.clone();
             call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
                 debug!("pretty printing source code {:?}", s);
                 let sess = annotation.sess();
-                *out = pprust_hir::print_crate(
-                    sess.source_map(),
-                    &sess.parse_sess,
-                    krate,
-                    src_name,
-                    src,
-                    annotation.pp_ann(),
-                )
+                let cm = sess.source_map();
+                *out = pprust_hir::print_crate(cm, krate, src_name, src, annotation.pp_ann())
             })
         }