Skip to content

Commit ca976f0

Browse files
committed
rustc: support overriding type printing in ty::print::Printer.
1 parent cec81e7 commit ca976f0

File tree

5 files changed

+283
-228
lines changed

5 files changed

+283
-228
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
459459

460460
type Path = Vec<String>;
461461
type Region = !;
462+
type Type = !;
462463

463464
fn print_region(
464465
self: PrintCx<'_, '_, '_, Self>,
@@ -467,6 +468,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
467468
Err(NonTrivialPath)
468469
}
469470

471+
fn print_type<'tcx>(
472+
self: PrintCx<'_, '_, 'tcx, Self>,
473+
_ty: Ty<'tcx>,
474+
) -> Result<Self::Type, Self::Error> {
475+
Err(NonTrivialPath)
476+
}
477+
470478
fn path_crate(
471479
self: PrintCx<'_, '_, '_, Self>,
472480
cnum: CrateNum,

src/librustc/ty/print.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ pub trait Printer: Sized {
254254

255255
type Path;
256256
type Region;
257+
type Type;
257258

258259
fn print_def_path(
259260
self: PrintCx<'_, '_, 'tcx, Self>,
@@ -280,6 +281,11 @@ pub trait Printer: Sized {
280281
region: ty::Region<'_>,
281282
) -> Result<Self::Region, Self::Error>;
282283

284+
fn print_type(
285+
self: PrintCx<'_, '_, 'tcx, Self>,
286+
ty: Ty<'tcx>,
287+
) -> Result<Self::Type, Self::Error>;
288+
283289
fn path_crate(
284290
self: PrintCx<'_, '_, '_, Self>,
285291
cnum: CrateNum,
@@ -319,7 +325,15 @@ pub trait Printer: Sized {
319325
}
320326

321327
/// Trait for printers that pretty-print using `fmt::Write` to the printer.
322-
pub trait PrettyPrinter: Printer<Error = fmt::Error, Path = Self, Region = Self> + fmt::Write {
328+
pub trait PrettyPrinter:
329+
Printer<
330+
Error = fmt::Error,
331+
Path = Self,
332+
Region = Self,
333+
Type = Self,
334+
> +
335+
fmt::Write
336+
{
323337
/// Enter a nested print context, for pretty-printing
324338
/// nested components in some larger context.
325339
fn nest<'a, 'gcx, 'tcx, E>(
@@ -900,6 +914,7 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
900914

901915
type Path = Self;
902916
type Region = Self;
917+
type Type = Self;
903918

904919
fn print_def_path(
905920
mut self: PrintCx<'_, '_, 'tcx, Self>,
@@ -1030,6 +1045,13 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
10301045
Ok(self.printer)
10311046
}
10321047

1048+
fn print_type(
1049+
self: PrintCx<'_, '_, 'tcx, Self>,
1050+
ty: Ty<'tcx>,
1051+
) -> Result<Self::Type, Self::Error> {
1052+
self.pretty_print_type(ty)
1053+
}
1054+
10331055
fn path_crate(
10341056
mut self: PrintCx<'_, '_, '_, Self>,
10351057
cnum: CrateNum,

0 commit comments

Comments
 (0)