Skip to content

Commit 4f608ab

Browse files
committed
rustc: support overriding type printing in ty::print::Printer.
1 parent 556d2b3 commit 4f608ab

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
@@ -253,6 +253,7 @@ pub trait Printer: Sized {
253253

254254
type Path;
255255
type Region;
256+
type Type;
256257

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

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

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

897911
type Path = Self;
898912
type Region = Self;
913+
type Type = Self;
899914

900915
fn print_def_path(
901916
mut self: PrintCx<'_, '_, 'tcx, Self>,
@@ -1026,6 +1041,13 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
10261041
Ok(self.printer)
10271042
}
10281043

1044+
fn print_type(
1045+
self: PrintCx<'_, '_, 'tcx, Self>,
1046+
ty: Ty<'tcx>,
1047+
) -> Result<Self::Type, Self::Error> {
1048+
self.pretty_print_type(ty)
1049+
}
1050+
10291051
fn path_crate(
10301052
mut self: PrintCx<'_, '_, '_, Self>,
10311053
cnum: CrateNum,

0 commit comments

Comments
 (0)