Skip to content

Commit 233d513

Browse files
committed
rustc: remove PrintCx from ty::Print and rely on printers carrying TyCtxt.
1 parent 4239191 commit 233d513

File tree

11 files changed

+889
-947
lines changed

11 files changed

+889
-947
lines changed

src/librustc/infer/error_reporting/mod.rs

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

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

454456
struct NonTrivialPath;
455457

456-
impl Printer for AbsolutePathPrinter {
458+
impl<'gcx, 'tcx> Printer<'gcx, 'tcx> for AbsolutePathPrinter<'_, 'gcx, 'tcx> {
457459
type Error = NonTrivialPath;
458460

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

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

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

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

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

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

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
@@ -339,17 +339,17 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
339339
}
340340
}
341341

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

352-
self.value.print(ty::print::PrintCx::new(self.tcx, printer))?;
352+
self.value.print(printer)?;
353353
Ok(())
354354
}
355355
}

src/librustc/mir/mod.rs

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

3838
pub use mir::interpret::AssertMessage;
3939

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

23812381
let f = &mut *fmt;
2382-
PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::ValueNS), |cx| {
2383-
let substs = cx.tcx.lift(&substs).expect("could not lift for printing");
2384-
cx.print_def_path(variant_def.did, Some(substs))?;
2382+
ty::tls::with(|tcx| {
2383+
let substs = tcx.lift(&substs).expect("could not lift for printing");
2384+
FmtPrinter::new(tcx, f, Namespace::ValueNS)
2385+
.print_def_path(variant_def.did, Some(substs))?;
23852386
Ok(())
23862387
})?;
23872388

src/librustc/ty/instance.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hir::Unsafety;
22
use hir::def::Namespace;
33
use hir::def_id::DefId;
44
use ty::{self, Ty, PolyFnSig, TypeFoldable, Substs, TyCtxt};
5-
use ty::print::{FmtPrinter, Printer, PrintCx};
5+
use ty::print::{FmtPrinter, Printer};
66
use traits;
77
use rustc_target::spec::abi::Abi;
88

@@ -175,9 +175,10 @@ impl<'tcx> InstanceDef<'tcx> {
175175

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

0 commit comments

Comments
 (0)