//! The various pretty-printing routines.
-use rustc::hir::map as hir_map;
-use rustc::session::config::{Input, PpMode, PpSourceMode};
-use rustc::session::Session;
-use rustc::ty::{self, TyCtxt};
-use rustc::util::common::ErrorReported;
use rustc_ast::ast;
use rustc_ast_pretty::pprust;
+use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def_id::LOCAL_CRATE;
-use rustc_hir::print as pprust_hir;
+use rustc_hir_pretty as pprust_hir;
+use rustc_middle::hir::map as hir_map;
+use rustc_middle::ty::{self, TyCtxt};
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
+use rustc_session::config::{Input, PpMode, PpSourceMode};
+use rustc_session::Session;
use rustc_span::FileName;
use std::cell::Cell;
///
/// (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 dyn pprust::PpAnn;
+ fn pp_ann(&self) -> &dyn pprust::PpAnn;
}
trait HirPrinterSupport<'hir>: pprust_hir::PpAnn {
/// Provides a uniform interface for re-extracting a reference to an
/// `hir_map::Map` from a value that now owns it.
- fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>>;
+ fn hir_map(&self) -> Option<hir_map::Map<'hir>>;
/// Produces the pretty-print annotation object.
///
/// (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 dyn pprust_hir::PpAnn;
+ fn pp_ann(&self) -> &dyn pprust_hir::PpAnn;
/// Computes an user-readable representation of a path, if possible.
fn node_path(&self, id: hir::HirId) -> Option<String> {
self.sess
}
- fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn {
+ fn pp_ann(&self) -> &dyn pprust::PpAnn {
self
}
}
self.sess
}
- fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> {
- self.tcx.map(|tcx| *tcx.hir())
+ fn hir_map(&self) -> Option<hir_map::Map<'hir>> {
+ self.tcx.map(|tcx| tcx.hir())
}
- fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
+ fn pp_ann(&self) -> &dyn pprust_hir::PpAnn {
self
}
}
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() as &dyn hir::intravisit::Map<'_>), state, nested)
}
}
}
self.sess
}
- fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn {
+ fn pp_ann(&self) -> &dyn pprust::PpAnn {
self
}
}
impl<'hir> pprust::PpAnn for IdentifiedAnnotation<'hir> {
fn pre(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) {
- match node {
- pprust::AnnNode::Expr(_) => s.popen(),
- _ => {}
+ if let pprust::AnnNode::Expr(_) = node {
+ s.popen();
}
}
fn post(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) {
self.sess
}
- fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> {
- self.tcx.map(|tcx| *tcx.hir())
+ fn hir_map(&self) -> Option<hir_map::Map<'hir>> {
+ self.tcx.map(|tcx| tcx.hir())
}
- fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
+ fn pp_ann(&self) -> &dyn pprust_hir::PpAnn {
self
}
}
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() as &dyn hir::intravisit::Map<'_>), state, nested)
}
}
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
- match node {
- pprust_hir::AnnNode::Expr(_) => s.popen(),
- _ => {}
+ if let pprust_hir::AnnNode::Expr(_) = node {
+ s.popen();
}
}
fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
&self.tcx.sess
}
- fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'tcx>> {
- Some(&self.tcx.hir())
+ fn hir_map(&self) -> Option<hir_map::Map<'tcx>> {
+ Some(self.tcx.hir())
}
- fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
+ fn pp_ann(&self) -> &dyn pprust_hir::PpAnn {
self
}
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);
+ let pp_ann = &(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>);
+ pprust_hir::PpAnn::nested(pp_ann, state, nested);
self.tables.set(old_tables);
}
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
- match node {
- pprust_hir::AnnNode::Expr(_) => s.popen(),
- _ => {}
+ if let pprust_hir::AnnNode::Expr(_) = node {
+ s.popen();
}
}
fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
- match node {
- pprust_hir::AnnNode::Expr(expr) => {
- s.s.space();
- s.s.word("as");
- s.s.space();
- s.s.word(self.tables.get().expr_ty(expr).to_string());
- s.pclose();
- }
- _ => {}
+ if let pprust_hir::AnnNode::Expr(expr) = node {
+ s.s.space();
+ s.s.word("as");
+ s.s.space();
+ s.s.word(self.tables.get().expr_ty(expr).to_string());
+ s.pclose();
}
}
}