Skip to content

Printer cleanups #144776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 12 additions & 34 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,12 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
where
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
{
self.pretty_print_in_binder(value)
let old_region_index = self.region_index;
let (new_value, _) = self.name_all_regions(value, WrapBinderMode::ForAll)?;
new_value.print(self)?;
self.region_index = old_region_index;
self.binder_depth -= 1;
Ok(())
}

fn wrap_binder<T, C: FnOnce(&T, &mut Self) -> Result<(), PrintError>>(
Expand All @@ -2468,7 +2473,12 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
self.pretty_wrap_binder(value, mode, f)
let old_region_index = self.region_index;
let (new_value, _) = self.name_all_regions(value, mode)?;
f(&new_value, self)?;
self.region_index = old_region_index;
self.binder_depth -= 1;
Ok(())
}

fn typed_value(
Expand Down Expand Up @@ -2855,38 +2865,6 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
Ok((new_value, map))
}

pub fn pretty_print_in_binder<T>(
&mut self,
value: &ty::Binder<'tcx, T>,
) -> Result<(), fmt::Error>
where
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
{
let old_region_index = self.region_index;
let (new_value, _) = self.name_all_regions(value, WrapBinderMode::ForAll)?;
new_value.print(self)?;
self.region_index = old_region_index;
self.binder_depth -= 1;
Ok(())
}

pub fn pretty_wrap_binder<T, C: FnOnce(&T, &mut Self) -> Result<(), fmt::Error>>(
&mut self,
value: &ty::Binder<'tcx, T>,
mode: WrapBinderMode,
f: C,
) -> Result<(), fmt::Error>
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
let old_region_index = self.region_index;
let (new_value, _) = self.name_all_regions(value, mode)?;
f(&new_value, self)?;
self.region_index = old_region_index;
self.binder_depth -= 1;
Ok(())
}

fn prepare_region_info<T>(&mut self, value: &ty::Binder<'tcx, T>)
where
T: TypeFoldable<TyCtxt<'tcx>>,
Expand Down