Skip to content

Commit

Permalink
rustc: make util::ppaux private.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Mar 15, 2019
1 parent 800ddb3 commit d0a1bf5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Expand Up @@ -768,7 +768,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}

/// For generic types with parameters with defaults, remove the parameters corresponding to
/// the defaults. This repeats a lot of the logic found in `PrintCx::parameterized`.
/// the defaults. This repeats a lot of the logic found in `ty::print::pretty`.
fn strip_generic_default_params(
&self,
def_id: DefId,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Expand Up @@ -135,7 +135,7 @@ pub mod ty;
pub mod util {
pub mod captures;
pub mod common;
pub mod ppaux;
mod ppaux;
pub mod nodemap;
pub mod profiling;
pub mod bug;
Expand Down
9 changes: 7 additions & 2 deletions src/librustc/mir/mod.rs
Expand Up @@ -34,7 +34,7 @@ use crate::ty::{
self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
UserTypeAnnotationIndex,
};
use crate::util::ppaux;
use crate::ty::print::{FmtPrinter, Printer, PrintCx};

pub use crate::mir::interpret::AssertMessage;

Expand Down Expand Up @@ -2406,7 +2406,12 @@ impl<'tcx> Debug for Rvalue<'tcx> {
AggregateKind::Adt(adt_def, variant, substs, _user_ty, _) => {
let variant_def = &adt_def.variants[variant];

ppaux::parameterized(fmt, variant_def.did, substs, Namespace::ValueNS)?;
let f = &mut *fmt;
PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::ValueNS), |cx| {
let substs = cx.tcx.lift(&substs).expect("could not lift for printing");
cx.print_def_path(variant_def.did, Some(substs), iter::empty())?;
Ok(())
})?;

match variant_def.ctor_kind {
CtorKind::Const => Ok(()),
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/traits/structural_impls.rs
Expand Up @@ -165,7 +165,8 @@ impl<'tcx> fmt::Display for traits::WhereClause<'tcx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use crate::traits::WhereClause::*;

// Bypass ppaux because it does not print out anonymous regions.
// Bypass `ty::print` because it does not print out anonymous regions.
// FIXME(eddyb) implement a custom `PrettyPrinter`, or move this to `ty::print`.
fn write_region_name<'tcx>(
r: ty::Region<'tcx>,
fmt: &mut fmt::Formatter<'_>
Expand Down Expand Up @@ -256,7 +257,7 @@ impl fmt::Display for traits::QuantifierKind {
}

/// Collect names for regions / types bound by a quantified goal / clause.
/// This collector does not try to do anything clever like in ppaux, it's just used
/// This collector does not try to do anything clever like in `ty::print`, it's just used
/// for debug output in tests anyway.
struct BoundNamesCollector {
// Just sort by name because `BoundRegion::BrNamed` does not have a `BoundVar` index anyway.
Expand Down
9 changes: 7 additions & 2 deletions src/librustc/ty/instance.rs
Expand Up @@ -2,10 +2,10 @@ use crate::hir::Unsafety;
use crate::hir::def::Namespace;
use crate::hir::def_id::DefId;
use crate::ty::{self, Ty, PolyFnSig, TypeFoldable, SubstsRef, TyCtxt};
use crate::ty::print::{FmtPrinter, Printer, PrintCx};
use crate::traits;
use rustc_target::spec::abi::Abi;
use rustc_macros::HashStable;
use crate::util::ppaux;

use std::fmt;
use std::iter;
Expand Down Expand Up @@ -176,7 +176,12 @@ impl<'tcx> InstanceDef<'tcx> {

impl<'tcx> fmt::Display for Instance<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ppaux::parameterized(f, self.def_id(), self.substs, Namespace::ValueNS)?;
PrintCx::with_tls_tcx(FmtPrinter::new(&mut *f, Namespace::ValueNS), |cx| {
let substs = cx.tcx.lift(&self.substs).expect("could not lift for printing");
cx.print_def_path(self.def_id(), Some(substs), iter::empty())?;
Ok(())
})?;

match self.def {
InstanceDef::Item(_) => Ok(()),
InstanceDef::VtableShim(_) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/print/pretty.rs
Expand Up @@ -1163,7 +1163,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
}
}

if self.config.is_verbose {
if self.tcx.sess.verbose() {
p!(write(
" closure_kind_ty={:?} closure_sig_ty={:?}",
substs.closure_kind_ty(did, self.tcx),
Expand Down
16 changes: 1 addition & 15 deletions src/librustc/util/ppaux.rs
@@ -1,7 +1,6 @@
use crate::hir;
use crate::hir::def::Namespace;
use crate::hir::def_id::DefId;
use crate::ty::subst::{Kind, SubstsRef, UnpackedKind};
use crate::ty::subst::{Kind, UnpackedKind};
use crate::ty::{self, ParamConst, Ty};
use crate::ty::print::{FmtPrinter, PrettyPrinter, PrintCx, Print, Printer};
use crate::mir::interpret::ConstValue;
Expand Down Expand Up @@ -142,19 +141,6 @@ macro_rules! define_scoped_cx {
};
}

pub fn parameterized<F: fmt::Write>(
f: &mut F,
did: DefId,
substs: SubstsRef<'_>,
ns: Namespace,
) -> fmt::Result {
PrintCx::with_tls_tcx(FmtPrinter::new(f, ns), |cx| {
let substs = cx.tcx.lift(&substs).expect("could not lift for printing");
cx.print_def_path(did, Some(substs), iter::empty())?;
Ok(())
})
}

define_print! {
('tcx) &'tcx ty::List<ty::ExistentialPredicate<'tcx>>, (self, cx) {
display {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_mir/monomorphize/item.rs
Expand Up @@ -216,9 +216,8 @@ impl<'a, 'tcx> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
// These keys are used by the handwritten auto-tests, so they need to be
// predictable and human-readable.
//
// Note: A lot of this could looks very similar to what's already in the
// ppaux module. It would be good to refactor things so we only have one
// parameterizable implementation for printing types.
// Note: A lot of this could looks very similar to what's already in `ty::print`.
// FIXME(eddyb) implement a custom `PrettyPrinter` for this.

/// Same as `unique_type_name()` but with the result pushed onto the given
/// `output` parameter.
Expand Down

0 comments on commit d0a1bf5

Please sign in to comment.