about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-23 20:59:19 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-03-24 06:25:03 +0100
commitb3866a5c9315d2f882ab9f306df82c5fa66989bf (patch)
tree1225a578eb0550e0cd7cbb1cc7c1da0b1e2fc049
parentb60d732efe924931f377e1f552ce6290b2ba8393 (diff)
downloadrust-b3866a5c9315d2f882ab9f306df82c5fa66989bf.tar.gz
rust-b3866a5c9315d2f882ab9f306df82c5fa66989bf.zip
move rustc_hir::print -> rustc_hir_pretty
-rw-r--r--Cargo.lock17
-rw-r--r--src/librustc/Cargo.toml1
-rw-r--r--src/librustc/hir/map/mod.rs8
-rw-r--r--src/librustc_driver/Cargo.toml1
-rw-r--r--src/librustc_driver/pretty.rs2
-rw-r--r--src/librustc_hir/Cargo.toml1
-rw-r--r--src/librustc_hir/lib.rs1
-rw-r--r--src/librustc_hir_pretty/Cargo.toml18
-rw-r--r--src/librustc_hir_pretty/lib.rs (renamed from src/librustc_hir/print.rs)11
-rw-r--r--src/librustc_metadata/Cargo.toml1
-rw-r--r--src/librustc_metadata/rmeta/encoder.rs4
-rw-r--r--src/librustc_typeck/Cargo.toml1
-rw-r--r--src/librustc_typeck/astconv.rs6
-rw-r--r--src/librustc_typeck/check/demand.rs13
-rw-r--r--src/librustc_typeck/check/mod.rs2
-rw-r--r--src/librustc_typeck/check/pat.rs2
-rw-r--r--src/librustc_typeck/check_unused.rs2
17 files changed, 64 insertions, 27 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 94305401ee9..02427ecb4b9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3114,6 +3114,7 @@ dependencies = [
  "rustc_errors",
  "rustc_feature",
  "rustc_hir",
+ "rustc_hir_pretty",
  "rustc_index",
  "rustc_macros",
  "rustc_query_system",
@@ -3654,6 +3655,7 @@ dependencies = [
  "rustc_errors",
  "rustc_feature",
  "rustc_hir",
+ "rustc_hir_pretty",
  "rustc_interface",
  "rustc_lint",
  "rustc_metadata",
@@ -3728,7 +3730,6 @@ dependencies = [
  "lazy_static 1.4.0",
  "log",
  "rustc_ast",
- "rustc_ast_pretty",
  "rustc_data_structures",
  "rustc_index",
  "rustc_macros",
@@ -3739,6 +3740,18 @@ dependencies = [
 ]
 
 [[package]]
+name = "rustc_hir_pretty"
+version = "0.0.0"
+dependencies = [
+ "rustc_ast",
+ "rustc_ast_pretty",
+ "rustc_data_structures",
+ "rustc_hir",
+ "rustc_span",
+ "rustc_target",
+]
+
+[[package]]
 name = "rustc_incremental"
 version = "0.0.0"
 dependencies = [
@@ -3888,6 +3901,7 @@ dependencies = [
  "rustc_errors",
  "rustc_expand",
  "rustc_hir",
+ "rustc_hir_pretty",
  "rustc_index",
  "rustc_session",
  "rustc_span",
@@ -4215,6 +4229,7 @@ dependencies = [
  "rustc_data_structures",
  "rustc_errors",
  "rustc_hir",
+ "rustc_hir_pretty",
  "rustc_index",
  "rustc_infer",
  "rustc_session",
diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml
index 47b94a2f1a4..d4464becb68 100644
--- a/src/librustc/Cargo.toml
+++ b/src/librustc/Cargo.toml
@@ -22,6 +22,7 @@ rustc_apfloat = { path = "../librustc_apfloat" }
 rustc_attr = { path = "../librustc_attr" }
 rustc_feature = { path = "../librustc_feature" }
 rustc_hir = { path = "../librustc_hir" }
+rustc_hir_pretty = { path = "../librustc_hir_pretty" }
 rustc_target = { path = "../librustc_target" }
 rustc_macros = { path = "../librustc_macros" }
 rustc_data_structures = { path = "../librustc_data_structures" }
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index eb8e57743b8..7154eb44e01 100644
--- a/src/librustc/hir/map/mod.rs
+++ b/src/librustc/hir/map/mod.rs
@@ -12,8 +12,8 @@ pub use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
 pub use rustc_hir::definitions::{Definitions, DisambiguatedDefPathData};
 use rustc_hir::intravisit;
 use rustc_hir::itemlikevisit::ItemLikeVisitor;
-use rustc_hir::print::Nested;
 use rustc_hir::*;
+use rustc_hir_pretty::Nested;
 use rustc_index::vec::IndexVec;
 use rustc_span::hygiene::MacroKind;
 use rustc_span::source_map::Spanned;
@@ -963,7 +963,7 @@ impl<'hir> Map<'hir> {
     }
 
     pub fn hir_to_pretty_string(&self, id: HirId) -> String {
-        print::to_string(self, |s| s.print_node(self.get(id)))
+        rustc_hir_pretty::to_string(self, |s| s.print_node(self.get(id)))
     }
 }
 
@@ -1048,8 +1048,8 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
 
 /// Identical to the `PpAnn` implementation for `hir::Crate`,
 /// except it avoids creating a dependency on the whole crate.
-impl<'hir> print::PpAnn for Map<'hir> {
-    fn nested(&self, state: &mut print::State<'_>, nested: print::Nested) {
+impl<'hir> rustc_hir_pretty::PpAnn for Map<'hir> {
+    fn nested(&self, state: &mut rustc_hir_pretty::State<'_>, nested: rustc_hir_pretty::Nested) {
         match nested {
             Nested::Item(id) => state.print_item(self.expect_item(id.id)),
             Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)),
diff --git a/src/librustc_driver/Cargo.toml b/src/librustc_driver/Cargo.toml
index aec10ee5ef5..3ca39b24c52 100644
--- a/src/librustc_driver/Cargo.toml
+++ b/src/librustc_driver/Cargo.toml
@@ -21,6 +21,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
 rustc_errors = { path = "../librustc_errors" }
 rustc_feature = { path = "../librustc_feature" }
 rustc_hir = { path = "../librustc_hir" }
+rustc_hir_pretty = { path = "../librustc_hir_pretty" }
 rustc_metadata = { path = "../librustc_metadata" }
 rustc_mir = { path = "../librustc_mir" }
 rustc_parse = { path = "../librustc_parse" }
diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs
index 1e5cc55a828..fe006f0e06c 100644
--- a/src/librustc_driver/pretty.rs
+++ b/src/librustc_driver/pretty.rs
@@ -7,7 +7,7 @@ use rustc_ast::ast;
 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_hir_pretty as pprust_hir;
 use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
 use rustc_session::config::{Input, PpMode, PpSourceMode};
 use rustc_session::Session;
diff --git a/src/librustc_hir/Cargo.toml b/src/librustc_hir/Cargo.toml
index 98598c4bcb5..811440fdeb9 100644
--- a/src/librustc_hir/Cargo.toml
+++ b/src/librustc_hir/Cargo.toml
@@ -10,7 +10,6 @@ path = "lib.rs"
 doctest = false
 
 [dependencies]
-rustc_ast_pretty = { path = "../librustc_ast_pretty" }
 rustc_target = { path = "../librustc_target" }
 rustc_macros = { path = "../librustc_macros" }
 rustc_data_structures = { path = "../librustc_data_structures" }
diff --git a/src/librustc_hir/lib.rs b/src/librustc_hir/lib.rs
index 5888bde919d..49692c73fad 100644
--- a/src/librustc_hir/lib.rs
+++ b/src/librustc_hir/lib.rs
@@ -24,7 +24,6 @@ pub mod intravisit;
 pub mod itemlikevisit;
 pub mod lang_items;
 pub mod pat_util;
-pub mod print;
 mod stable_hash_impls;
 mod target;
 pub mod weak_lang_items;
diff --git a/src/librustc_hir_pretty/Cargo.toml b/src/librustc_hir_pretty/Cargo.toml
new file mode 100644
index 00000000000..6a9339b4b9c
--- /dev/null
+++ b/src/librustc_hir_pretty/Cargo.toml
@@ -0,0 +1,18 @@
+[package]
+authors = ["The Rust Project Developers"]
+name = "rustc_hir_pretty"
+version = "0.0.0"
+edition = "2018"
+
+[lib]
+name = "rustc_hir_pretty"
+path = "lib.rs"
+doctest = false
+
+[dependencies]
+rustc_ast_pretty = { path = "../librustc_ast_pretty" }
+rustc_hir = { path = "../librustc_hir" }
+rustc_target = { path = "../librustc_target" }
+rustc_data_structures = { path = "../librustc_data_structures" }
+rustc_span = { path = "../librustc_span" }
+rustc_ast = { path = "../librustc_ast" }
diff --git a/src/librustc_hir/print.rs b/src/librustc_hir_pretty/lib.rs
index f33ed3a7239..dc82fb03433 100644
--- a/src/librustc_hir/print.rs
+++ b/src/librustc_hir_pretty/lib.rs
@@ -3,15 +3,14 @@ use rustc_ast::util::parser::{self, AssocOp, Fixity};
 use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
 use rustc_ast_pretty::pp::{self, Breaks};
 use rustc_ast_pretty::pprust::{Comments, PrintState};
+use rustc_hir as hir;
+use rustc_hir::{GenericArg, GenericParam, GenericParamKind, Node};
+use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
 use rustc_span::source_map::{SourceMap, Spanned};
 use rustc_span::symbol::{kw, IdentPrinter};
 use rustc_span::{self, BytePos, FileName};
 use rustc_target::spec::abi::Abi;
 
-use crate::hir;
-use crate::hir::{GenericArg, GenericParam, GenericParamKind, Node};
-use crate::hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
-
 use std::borrow::Cow;
 use std::cell::Cell;
 use std::vec;
@@ -47,7 +46,7 @@ pub struct NoAnn;
 impl PpAnn for NoAnn {}
 pub const NO_ANN: &dyn PpAnn = &NoAnn;
 
-impl PpAnn for hir::Crate<'a> {
+impl PpAnn for hir::Crate<'_> {
     fn try_fetch_item(&self, item: hir::HirId) -> Option<&hir::Item<'_>> {
         Some(self.item(item))
     }
@@ -1092,7 +1091,7 @@ impl<'a> State<'a> {
         &mut self,
         qpath: &hir::QPath<'_>,
         fields: &[hir::Field<'_>],
-        wth: &Option<&'hir hir::Expr<'_>>,
+        wth: &Option<&hir::Expr<'_>>,
     ) {
         self.print_qpath(qpath, true);
         self.s.word("{");
diff --git a/src/librustc_metadata/Cargo.toml b/src/librustc_metadata/Cargo.toml
index 088cba83ef9..ea439b1f41d 100644
--- a/src/librustc_metadata/Cargo.toml
+++ b/src/librustc_metadata/Cargo.toml
@@ -19,6 +19,7 @@ rustc_attr = { path = "../librustc_attr" }
 rustc_data_structures = { path = "../librustc_data_structures" }
 rustc_errors = { path = "../librustc_errors" }
 rustc_hir = { path = "../librustc_hir" }
+rustc_hir_pretty = { path = "../librustc_hir_pretty" }
 rustc_target = { path = "../librustc_target" }
 rustc_index = { path = "../librustc_index" }
 rustc_serialize = { path = "../libserialize", package = "serialize" }
diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs
index 52124fd3abb..84165501427 100644
--- a/src/librustc_metadata/rmeta/encoder.rs
+++ b/src/librustc_metadata/rmeta/encoder.rs
@@ -830,7 +830,7 @@ impl EncodeContext<'tcx> {
         record!(self.per_def.kind[def_id] <- match trait_item.kind {
             ty::AssocKind::Const => {
                 let rendered =
-                    hir::print::to_string(&self.tcx.hir(), |s| s.print_trait_item(ast_item));
+                    rustc_hir_pretty::to_string(&self.tcx.hir(), |s| s.print_trait_item(ast_item));
                 let rendered_const = self.lazy(RenderedConst(rendered));
 
                 EntryKind::AssocConst(
@@ -1048,7 +1048,7 @@ impl EncodeContext<'tcx> {
 
     fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> Lazy<RenderedConst> {
         let body = self.tcx.hir().body(body_id);
-        let rendered = hir::print::to_string(&self.tcx.hir(), |s| s.print_expr(&body.value));
+        let rendered = rustc_hir_pretty::to_string(&self.tcx.hir(), |s| s.print_expr(&body.value));
         let rendered_const = &RenderedConst(rendered);
         self.lazy(rendered_const)
     }
diff --git a/src/librustc_typeck/Cargo.toml b/src/librustc_typeck/Cargo.toml
index e61a36f844f..a76f920ce9b 100644
--- a/src/librustc_typeck/Cargo.toml
+++ b/src/librustc_typeck/Cargo.toml
@@ -18,6 +18,7 @@ rustc_attr = { path = "../librustc_attr" }
 rustc_data_structures = { path = "../librustc_data_structures" }
 rustc_errors = { path = "../librustc_errors" }
 rustc_hir = { path = "../librustc_hir" }
+rustc_hir_pretty = { path = "../librustc_hir_pretty" }
 rustc_target = { path = "../librustc_target" }
 rustc_session = { path = "../librustc_session" }
 smallvec = { version = "1.0", features = ["union", "may_dangle"] }
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 86737a819a7..be515d763cc 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -21,8 +21,8 @@ use rustc_hir as hir;
 use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
 use rustc_hir::def_id::DefId;
 use rustc_hir::intravisit::{walk_generics, Visitor};
-use rustc_hir::print;
 use rustc_hir::{Constness, GenericArg, GenericArgs};
+use rustc_hir_pretty::{to_string, NO_ANN};
 use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, LATE_BOUND_LIFETIME_ARGUMENTS};
 use rustc_session::parse::feature_err;
 use rustc_session::Session;
@@ -1132,7 +1132,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                             .and_then(|args| args.args.get(0))
                             .and_then(|arg| match arg {
                                 hir::GenericArg::Type(ty) => {
-                                    Some(print::to_string(print::NO_ANN, |s| s.print_type(ty)))
+                                    Some(to_string(NO_ANN, |s| s.print_type(ty)))
                                 }
                                 _ => None,
                             })
@@ -1143,7 +1143,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                             .iter()
                             .filter_map(|b| match (b.ident.as_str() == "Output", &b.kind) {
                                 (true, hir::TypeBindingKind::Equality { ty }) => {
-                                    Some(print::to_string(print::NO_ANN, |s| s.print_type(ty)))
+                                    Some(to_string(NO_ANN, |s| s.print_type(ty)))
                                 }
                                 _ => None,
                             })
diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs
index 0556c80e4f7..40c056a7641 100644
--- a/src/librustc_typeck/check/demand.rs
+++ b/src/librustc_typeck/check/demand.rs
@@ -9,7 +9,8 @@ use rustc::ty::{self, AssocItem, Ty};
 use rustc_ast::util::parser::PREC_POSTFIX;
 use rustc_errors::{Applicability, DiagnosticBuilder};
 use rustc_hir as hir;
-use rustc_hir::{is_range_literal, print, Node};
+use rustc_hir::{is_range_literal, Node};
+use rustc_hir_pretty::{to_string, NO_ANN};
 use rustc_span::symbol::sym;
 use rustc_span::Span;
 
@@ -198,10 +199,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 .peekable();
 
             if compatible_variants.peek().is_some() {
-                let expr_text =
-                    self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or_else(|_| {
-                        print::to_string(print::NO_ANN, |s| s.print_expr(expr))
-                    });
+                let expr_text = self
+                    .tcx
+                    .sess
+                    .source_map()
+                    .span_to_snippet(expr.span)
+                    .unwrap_or_else(|_| to_string(NO_ANN, |s| s.print_expr(expr)));
                 let suggestions = compatible_variants.map(|v| format!("{}({})", v, expr_text));
                 let msg = "try using a variant of the expected enum";
                 err.span_suggestions(expr.span, msg, suggestions, Applicability::MaybeIncorrect);
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 085510452c4..7855b4b761d 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -2663,7 +2663,7 @@ fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span, qpath: &
         E0533,
         "expected unit struct, unit variant or constant, found {} `{}`",
         res.descr(),
-        hir::print::to_string(&tcx.hir(), |s| s.print_qpath(qpath, false))
+        rustc_hir_pretty::to_string(&tcx.hir(), |s| s.print_qpath(qpath, false))
     )
     .emit();
 }
diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs
index 0d38fa98bd7..d2290d4a583 100644
--- a/src/librustc_typeck/check/pat.rs
+++ b/src/librustc_typeck/check/pat.rs
@@ -794,7 +794,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             let msg = format!(
                 "expected tuple struct or tuple variant, found {} `{}`",
                 res.descr(),
-                hir::print::to_string(&tcx.hir(), |s| s.print_qpath(qpath, false)),
+                rustc_hir_pretty::to_string(&tcx.hir(), |s| s.print_qpath(qpath, false)),
             );
             let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg);
             match (res, &pat.kind) {
diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs
index d0414af5b21..fbc8c3327bf 100644
--- a/src/librustc_typeck/check_unused.rs
+++ b/src/librustc_typeck/check_unused.rs
@@ -5,7 +5,7 @@ use rustc_errors::Applicability;
 use rustc_hir as hir;
 use rustc_hir::def_id::{DefId, DefIdSet, LOCAL_CRATE};
 use rustc_hir::itemlikevisit::ItemLikeVisitor;
-use rustc_hir::print::visibility_qualified;
+use rustc_hir_pretty::visibility_qualified;
 use rustc_session::lint;
 use rustc_span::Span;