Skip to content

Commit 52b4f2d

Browse files
committed
rustc: remove PrintCx from ty::Print and rely on printers carrying TyCtxt.
1 parent 2a65682 commit 52b4f2d

File tree

11 files changed

+919
-976
lines changed

11 files changed

+919
-976
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -445,82 +445,82 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
445445
sp: Span,
446446
) {
447447
use hir::def_id::CrateNum;
448-
use ty::print::{PrintCx, Printer};
448+
use ty::print::Printer;
449449
use ty::subst::Kind;
450450

451-
struct AbsolutePathPrinter;
451+
struct AbsolutePathPrinter<'a, 'gcx, 'tcx> {
452+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
453+
}
452454

453455
struct NonTrivialPath;
454456

455-
impl Printer for AbsolutePathPrinter {
457+
impl<'gcx, 'tcx> Printer<'gcx, 'tcx> for AbsolutePathPrinter<'_, 'gcx, 'tcx> {
456458
type Error = NonTrivialPath;
457459

458460
type Path = Vec<String>;
459461
type Region = !;
460462
type Type = !;
461463
type DynExistential = !;
462464

465+
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx> {
466+
self.tcx
467+
}
468+
463469
fn print_region(
464-
self: PrintCx<'_, '_, '_, Self>,
470+
self,
465471
_region: ty::Region<'_>,
466472
) -> Result<Self::Region, Self::Error> {
467473
Err(NonTrivialPath)
468474
}
469475

470-
fn print_type<'tcx>(
471-
self: PrintCx<'_, '_, 'tcx, Self>,
476+
fn print_type(
477+
self,
472478
_ty: Ty<'tcx>,
473479
) -> Result<Self::Type, Self::Error> {
474480
Err(NonTrivialPath)
475481
}
476482

477-
fn print_dyn_existential<'tcx>(
478-
self: PrintCx<'_, '_, 'tcx, Self>,
483+
fn print_dyn_existential(
484+
self,
479485
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
480486
) -> Result<Self::DynExistential, Self::Error> {
481487
Err(NonTrivialPath)
482488
}
483489

484490
fn path_crate(
485-
self: PrintCx<'_, '_, '_, Self>,
491+
self,
486492
cnum: CrateNum,
487493
) -> Result<Self::Path, Self::Error> {
488494
Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
489495
}
490-
fn path_qualified<'tcx>(
491-
self: PrintCx<'_, '_, 'tcx, Self>,
496+
fn path_qualified(
497+
self,
492498
_self_ty: Ty<'tcx>,
493499
_trait_ref: Option<ty::TraitRef<'tcx>>,
494500
) -> Result<Self::Path, Self::Error> {
495501
Err(NonTrivialPath)
496502
}
497503

498-
fn path_append_impl<'gcx, 'tcx>(
499-
self: PrintCx<'_, 'gcx, 'tcx, Self>,
500-
_print_prefix: impl FnOnce(
501-
PrintCx<'_, 'gcx, 'tcx, Self>,
502-
) -> Result<Self::Path, Self::Error>,
504+
fn path_append_impl(
505+
self,
506+
_print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
503507
_self_ty: Ty<'tcx>,
504508
_trait_ref: Option<ty::TraitRef<'tcx>>,
505509
) -> Result<Self::Path, Self::Error> {
506510
Err(NonTrivialPath)
507511
}
508-
fn path_append<'gcx, 'tcx>(
509-
self: PrintCx<'_, 'gcx, 'tcx, Self>,
510-
print_prefix: impl FnOnce(
511-
PrintCx<'_, 'gcx, 'tcx, Self>,
512-
) -> Result<Self::Path, Self::Error>,
512+
fn path_append(
513+
self,
514+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
513515
text: &str,
514516
) -> Result<Self::Path, Self::Error> {
515517
let mut path = print_prefix(self)?;
516518
path.push(text.to_string());
517519
Ok(path)
518520
}
519-
fn path_generic_args<'gcx, 'tcx>(
520-
self: PrintCx<'_, 'gcx, 'tcx, Self>,
521-
print_prefix: impl FnOnce(
522-
PrintCx<'_, 'gcx, 'tcx, Self>,
523-
) -> Result<Self::Path, Self::Error>,
521+
fn path_generic_args(
522+
self,
523+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
524524
_args: &[Kind<'tcx>],
525525
) -> Result<Self::Path, Self::Error> {
526526
print_prefix(self)
@@ -532,7 +532,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
532532
// module we could have false positives
533533
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
534534
let abs_path = |def_id| {
535-
PrintCx::new(self.tcx, AbsolutePathPrinter)
535+
AbsolutePathPrinter { tcx: self.tcx }
536536
.print_def_path(def_id, None)
537537
};
538538

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
8080
}
8181

8282
let mut s = String::new();
83-
let mut printer = ty::print::FmtPrinter::new(&mut s, Namespace::TypeNS);
83+
let mut printer = ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::TypeNS);
8484
if let Some(highlight) = highlight {
8585
printer.region_highlight_mode = highlight;
8686
}
87-
let _ = ty.print(ty::print::PrintCx::new(self.tcx, printer));
87+
let _ = ty.print(printer);
8888
s
8989
}
9090

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,17 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
337337
}
338338
}
339339

340-
impl<'tcx, T> fmt::Display for Highlighted<'_, '_, 'tcx, T>
341-
where T: for<'a, 'b> Print<'tcx,
342-
FmtPrinter<&'a mut fmt::Formatter<'b>>,
340+
impl<'a, 'gcx, 'tcx, T> fmt::Display for Highlighted<'a, 'gcx, 'tcx, T>
341+
where T: for<'b, 'c> Print<'gcx, 'tcx,
342+
FmtPrinter<'a, 'gcx, 'tcx, &'b mut fmt::Formatter<'c>>,
343343
Error = fmt::Error,
344344
>,
345345
{
346346
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
347-
let mut printer = ty::print::FmtPrinter::new(f, Namespace::TypeNS);
347+
let mut printer = ty::print::FmtPrinter::new(self.tcx, f, Namespace::TypeNS);
348348
printer.region_highlight_mode = self.highlight;
349349

350-
self.value.print(ty::print::PrintCx::new(self.tcx, printer))?;
350+
self.value.print(printer)?;
351351
Ok(())
352352
}
353353
}

src/librustc/mir/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::ty::{
3434
self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
3535
UserTypeAnnotationIndex,
3636
};
37-
use crate::ty::print::{FmtPrinter, Printer, PrintCx};
37+
use crate::ty::print::{FmtPrinter, Printer};
3838

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

@@ -2407,9 +2407,10 @@ impl<'tcx> Debug for Rvalue<'tcx> {
24072407
let variant_def = &adt_def.variants[variant];
24082408

24092409
let f = &mut *fmt;
2410-
PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::ValueNS), |cx| {
2411-
let substs = cx.tcx.lift(&substs).expect("could not lift for printing");
2412-
cx.print_def_path(variant_def.did, Some(substs))?;
2410+
ty::tls::with(|tcx| {
2411+
let substs = tcx.lift(&substs).expect("could not lift for printing");
2412+
FmtPrinter::new(tcx, f, Namespace::ValueNS)
2413+
.print_def_path(variant_def.did, Some(substs))?;
24132414
Ok(())
24142415
})?;
24152416

src/librustc/ty/instance.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::hir::Unsafety;
22
use crate::hir::def::Namespace;
33
use crate::hir::def_id::DefId;
44
use crate::ty::{self, Ty, PolyFnSig, TypeFoldable, SubstsRef, TyCtxt};
5-
use crate::ty::print::{FmtPrinter, Printer, PrintCx};
5+
use crate::ty::print::{FmtPrinter, Printer};
66
use crate::traits;
77
use rustc_target::spec::abi::Abi;
88
use rustc_macros::HashStable;
@@ -176,9 +176,10 @@ impl<'tcx> InstanceDef<'tcx> {
176176

177177
impl<'tcx> fmt::Display for Instance<'tcx> {
178178
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179-
PrintCx::with_tls_tcx(FmtPrinter::new(&mut *f, Namespace::ValueNS), |cx| {
180-
let substs = cx.tcx.lift(&self.substs).expect("could not lift for printing");
181-
cx.print_def_path(self.def_id(), Some(substs))?;
179+
ty::tls::with(|tcx| {
180+
let substs = tcx.lift(&self.substs).expect("could not lift for printing");
181+
FmtPrinter::new(tcx, &mut *f, Namespace::ValueNS)
182+
.print_def_path(self.def_id(), Some(substs))?;
182183
Ok(())
183184
})?;
184185

0 commit comments

Comments
 (0)