move rustc_hir::print -> rustc_hir_pretty
This commit is contained in:
parent
b60d732efe
commit
b3866a5c93
17
Cargo.lock
17
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",
|
||||
@ -3738,6 +3739,18 @@ dependencies = [
|
||||
"smallvec 1.0.0",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@ -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",
|
||||
|
@ -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" }
|
||||
|
@ -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)),
|
||||
|
@ -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" }
|
||||
|
@ -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;
|
||||
|
@ -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" }
|
||||
|
@ -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;
|
||||
|
18
src/librustc_hir_pretty/Cargo.toml
Normal file
18
src/librustc_hir_pretty/Cargo.toml
Normal file
@ -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" }
|
@ -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("{");
|
@ -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" }
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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"] }
|
||||
|
@ -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,
|
||||
})
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user