Skip to content

Commit b3866a5

Browse files
committed
move rustc_hir::print -> rustc_hir_pretty
1 parent b60d732 commit b3866a5

File tree

17 files changed

+64
-27
lines changed

17 files changed

+64
-27
lines changed

Cargo.lock

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,7 @@ dependencies = [
31143114
"rustc_errors",
31153115
"rustc_feature",
31163116
"rustc_hir",
3117+
"rustc_hir_pretty",
31173118
"rustc_index",
31183119
"rustc_macros",
31193120
"rustc_query_system",
@@ -3654,6 +3655,7 @@ dependencies = [
36543655
"rustc_errors",
36553656
"rustc_feature",
36563657
"rustc_hir",
3658+
"rustc_hir_pretty",
36573659
"rustc_interface",
36583660
"rustc_lint",
36593661
"rustc_metadata",
@@ -3728,7 +3730,6 @@ dependencies = [
37283730
"lazy_static 1.4.0",
37293731
"log",
37303732
"rustc_ast",
3731-
"rustc_ast_pretty",
37323733
"rustc_data_structures",
37333734
"rustc_index",
37343735
"rustc_macros",
@@ -3738,6 +3739,18 @@ dependencies = [
37383739
"smallvec 1.0.0",
37393740
]
37403741

3742+
[[package]]
3743+
name = "rustc_hir_pretty"
3744+
version = "0.0.0"
3745+
dependencies = [
3746+
"rustc_ast",
3747+
"rustc_ast_pretty",
3748+
"rustc_data_structures",
3749+
"rustc_hir",
3750+
"rustc_span",
3751+
"rustc_target",
3752+
]
3753+
37413754
[[package]]
37423755
name = "rustc_incremental"
37433756
version = "0.0.0"
@@ -3888,6 +3901,7 @@ dependencies = [
38883901
"rustc_errors",
38893902
"rustc_expand",
38903903
"rustc_hir",
3904+
"rustc_hir_pretty",
38913905
"rustc_index",
38923906
"rustc_session",
38933907
"rustc_span",
@@ -4215,6 +4229,7 @@ dependencies = [
42154229
"rustc_data_structures",
42164230
"rustc_errors",
42174231
"rustc_hir",
4232+
"rustc_hir_pretty",
42184233
"rustc_index",
42194234
"rustc_infer",
42204235
"rustc_session",

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ rustc_apfloat = { path = "../librustc_apfloat" }
2222
rustc_attr = { path = "../librustc_attr" }
2323
rustc_feature = { path = "../librustc_feature" }
2424
rustc_hir = { path = "../librustc_hir" }
25+
rustc_hir_pretty = { path = "../librustc_hir_pretty" }
2526
rustc_target = { path = "../librustc_target" }
2627
rustc_macros = { path = "../librustc_macros" }
2728
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc/hir/map/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
1212
pub use rustc_hir::definitions::{Definitions, DisambiguatedDefPathData};
1313
use rustc_hir::intravisit;
1414
use rustc_hir::itemlikevisit::ItemLikeVisitor;
15-
use rustc_hir::print::Nested;
1615
use rustc_hir::*;
16+
use rustc_hir_pretty::Nested;
1717
use rustc_index::vec::IndexVec;
1818
use rustc_span::hygiene::MacroKind;
1919
use rustc_span::source_map::Spanned;
@@ -963,7 +963,7 @@ impl<'hir> Map<'hir> {
963963
}
964964

965965
pub fn hir_to_pretty_string(&self, id: HirId) -> String {
966-
print::to_string(self, |s| s.print_node(self.get(id)))
966+
rustc_hir_pretty::to_string(self, |s| s.print_node(self.get(id)))
967967
}
968968
}
969969

@@ -1048,8 +1048,8 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
10481048

10491049
/// Identical to the `PpAnn` implementation for `hir::Crate`,
10501050
/// except it avoids creating a dependency on the whole crate.
1051-
impl<'hir> print::PpAnn for Map<'hir> {
1052-
fn nested(&self, state: &mut print::State<'_>, nested: print::Nested) {
1051+
impl<'hir> rustc_hir_pretty::PpAnn for Map<'hir> {
1052+
fn nested(&self, state: &mut rustc_hir_pretty::State<'_>, nested: rustc_hir_pretty::Nested) {
10531053
match nested {
10541054
Nested::Item(id) => state.print_item(self.expect_item(id.id)),
10551055
Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)),

src/librustc_driver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
2121
rustc_errors = { path = "../librustc_errors" }
2222
rustc_feature = { path = "../librustc_feature" }
2323
rustc_hir = { path = "../librustc_hir" }
24+
rustc_hir_pretty = { path = "../librustc_hir_pretty" }
2425
rustc_metadata = { path = "../librustc_metadata" }
2526
rustc_mir = { path = "../librustc_mir" }
2627
rustc_parse = { path = "../librustc_parse" }

src/librustc_driver/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_ast::ast;
77
use rustc_ast_pretty::pprust;
88
use rustc_hir as hir;
99
use rustc_hir::def_id::LOCAL_CRATE;
10-
use rustc_hir::print as pprust_hir;
10+
use rustc_hir_pretty as pprust_hir;
1111
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
1212
use rustc_session::config::{Input, PpMode, PpSourceMode};
1313
use rustc_session::Session;

src/librustc_hir/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ path = "lib.rs"
1010
doctest = false
1111

1212
[dependencies]
13-
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
1413
rustc_target = { path = "../librustc_target" }
1514
rustc_macros = { path = "../librustc_macros" }
1615
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_hir/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub mod intravisit;
2424
pub mod itemlikevisit;
2525
pub mod lang_items;
2626
pub mod pat_util;
27-
pub mod print;
2827
mod stable_hash_impls;
2928
mod target;
3029
pub mod weak_lang_items;

src/librustc_hir_pretty/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_hir_pretty"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
name = "rustc_hir_pretty"
9+
path = "lib.rs"
10+
doctest = false
11+
12+
[dependencies]
13+
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
14+
rustc_hir = { path = "../librustc_hir" }
15+
rustc_target = { path = "../librustc_target" }
16+
rustc_data_structures = { path = "../librustc_data_structures" }
17+
rustc_span = { path = "../librustc_span" }
18+
rustc_ast = { path = "../librustc_ast" }

src/librustc_hir/print.rs renamed to src/librustc_hir_pretty/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ use rustc_ast::util::parser::{self, AssocOp, Fixity};
33
use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
44
use rustc_ast_pretty::pp::{self, Breaks};
55
use rustc_ast_pretty::pprust::{Comments, PrintState};
6+
use rustc_hir as hir;
7+
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, Node};
8+
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
69
use rustc_span::source_map::{SourceMap, Spanned};
710
use rustc_span::symbol::{kw, IdentPrinter};
811
use rustc_span::{self, BytePos, FileName};
912
use rustc_target::spec::abi::Abi;
1013

11-
use crate::hir;
12-
use crate::hir::{GenericArg, GenericParam, GenericParamKind, Node};
13-
use crate::hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
14-
1514
use std::borrow::Cow;
1615
use std::cell::Cell;
1716
use std::vec;
@@ -47,7 +46,7 @@ pub struct NoAnn;
4746
impl PpAnn for NoAnn {}
4847
pub const NO_ANN: &dyn PpAnn = &NoAnn;
4948

50-
impl PpAnn for hir::Crate<'a> {
49+
impl PpAnn for hir::Crate<'_> {
5150
fn try_fetch_item(&self, item: hir::HirId) -> Option<&hir::Item<'_>> {
5251
Some(self.item(item))
5352
}
@@ -1092,7 +1091,7 @@ impl<'a> State<'a> {
10921091
&mut self,
10931092
qpath: &hir::QPath<'_>,
10941093
fields: &[hir::Field<'_>],
1095-
wth: &Option<&'hir hir::Expr<'_>>,
1094+
wth: &Option<&hir::Expr<'_>>,
10961095
) {
10971096
self.print_qpath(qpath, true);
10981097
self.s.word("{");

src/librustc_metadata/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ rustc_attr = { path = "../librustc_attr" }
1919
rustc_data_structures = { path = "../librustc_data_structures" }
2020
rustc_errors = { path = "../librustc_errors" }
2121
rustc_hir = { path = "../librustc_hir" }
22+
rustc_hir_pretty = { path = "../librustc_hir_pretty" }
2223
rustc_target = { path = "../librustc_target" }
2324
rustc_index = { path = "../librustc_index" }
2425
rustc_serialize = { path = "../libserialize", package = "serialize" }

src/librustc_metadata/rmeta/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ impl EncodeContext<'tcx> {
830830
record!(self.per_def.kind[def_id] <- match trait_item.kind {
831831
ty::AssocKind::Const => {
832832
let rendered =
833-
hir::print::to_string(&self.tcx.hir(), |s| s.print_trait_item(ast_item));
833+
rustc_hir_pretty::to_string(&self.tcx.hir(), |s| s.print_trait_item(ast_item));
834834
let rendered_const = self.lazy(RenderedConst(rendered));
835835

836836
EntryKind::AssocConst(
@@ -1048,7 +1048,7 @@ impl EncodeContext<'tcx> {
10481048

10491049
fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> Lazy<RenderedConst> {
10501050
let body = self.tcx.hir().body(body_id);
1051-
let rendered = hir::print::to_string(&self.tcx.hir(), |s| s.print_expr(&body.value));
1051+
let rendered = rustc_hir_pretty::to_string(&self.tcx.hir(), |s| s.print_expr(&body.value));
10521052
let rendered_const = &RenderedConst(rendered);
10531053
self.lazy(rendered_const)
10541054
}

src/librustc_typeck/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rustc_attr = { path = "../librustc_attr" }
1818
rustc_data_structures = { path = "../librustc_data_structures" }
1919
rustc_errors = { path = "../librustc_errors" }
2020
rustc_hir = { path = "../librustc_hir" }
21+
rustc_hir_pretty = { path = "../librustc_hir_pretty" }
2122
rustc_target = { path = "../librustc_target" }
2223
rustc_session = { path = "../librustc_session" }
2324
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

src/librustc_typeck/astconv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use rustc_hir as hir;
2121
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
2222
use rustc_hir::def_id::DefId;
2323
use rustc_hir::intravisit::{walk_generics, Visitor};
24-
use rustc_hir::print;
2524
use rustc_hir::{Constness, GenericArg, GenericArgs};
25+
use rustc_hir_pretty::{to_string, NO_ANN};
2626
use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, LATE_BOUND_LIFETIME_ARGUMENTS};
2727
use rustc_session::parse::feature_err;
2828
use rustc_session::Session;
@@ -1132,7 +1132,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11321132
.and_then(|args| args.args.get(0))
11331133
.and_then(|arg| match arg {
11341134
hir::GenericArg::Type(ty) => {
1135-
Some(print::to_string(print::NO_ANN, |s| s.print_type(ty)))
1135+
Some(to_string(NO_ANN, |s| s.print_type(ty)))
11361136
}
11371137
_ => None,
11381138
})
@@ -1143,7 +1143,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11431143
.iter()
11441144
.filter_map(|b| match (b.ident.as_str() == "Output", &b.kind) {
11451145
(true, hir::TypeBindingKind::Equality { ty }) => {
1146-
Some(print::to_string(print::NO_ANN, |s| s.print_type(ty)))
1146+
Some(to_string(NO_ANN, |s| s.print_type(ty)))
11471147
}
11481148
_ => None,
11491149
})

src/librustc_typeck/check/demand.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use rustc::ty::{self, AssocItem, Ty};
99
use rustc_ast::util::parser::PREC_POSTFIX;
1010
use rustc_errors::{Applicability, DiagnosticBuilder};
1111
use rustc_hir as hir;
12-
use rustc_hir::{is_range_literal, print, Node};
12+
use rustc_hir::{is_range_literal, Node};
13+
use rustc_hir_pretty::{to_string, NO_ANN};
1314
use rustc_span::symbol::sym;
1415
use rustc_span::Span;
1516

@@ -198,10 +199,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
198199
.peekable();
199200

200201
if compatible_variants.peek().is_some() {
201-
let expr_text =
202-
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or_else(|_| {
203-
print::to_string(print::NO_ANN, |s| s.print_expr(expr))
204-
});
202+
let expr_text = self
203+
.tcx
204+
.sess
205+
.source_map()
206+
.span_to_snippet(expr.span)
207+
.unwrap_or_else(|_| to_string(NO_ANN, |s| s.print_expr(expr)));
205208
let suggestions = compatible_variants.map(|v| format!("{}({})", v, expr_text));
206209
let msg = "try using a variant of the expected enum";
207210
err.span_suggestions(expr.span, msg, suggestions, Applicability::MaybeIncorrect);

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span, qpath: &
26632663
E0533,
26642664
"expected unit struct, unit variant or constant, found {} `{}`",
26652665
res.descr(),
2666-
hir::print::to_string(&tcx.hir(), |s| s.print_qpath(qpath, false))
2666+
rustc_hir_pretty::to_string(&tcx.hir(), |s| s.print_qpath(qpath, false))
26672667
)
26682668
.emit();
26692669
}

src/librustc_typeck/check/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
794794
let msg = format!(
795795
"expected tuple struct or tuple variant, found {} `{}`",
796796
res.descr(),
797-
hir::print::to_string(&tcx.hir(), |s| s.print_qpath(qpath, false)),
797+
rustc_hir_pretty::to_string(&tcx.hir(), |s| s.print_qpath(qpath, false)),
798798
);
799799
let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg);
800800
match (res, &pat.kind) {

src/librustc_typeck/check_unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_errors::Applicability;
55
use rustc_hir as hir;
66
use rustc_hir::def_id::{DefId, DefIdSet, LOCAL_CRATE};
77
use rustc_hir::itemlikevisit::ItemLikeVisitor;
8-
use rustc_hir::print::visibility_qualified;
8+
use rustc_hir_pretty::visibility_qualified;
99
use rustc_session::lint;
1010
use rustc_span::Span;
1111

0 commit comments

Comments
 (0)