Trait rustc_middle::ty::print::pretty::PrettyPrinter
source · pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = Error, Path = Self, Region = Self, Type = Self, DynExistential = Self, Const = Self> + Write {
Show 31 methods
// Required methods
fn generic_delimiters(
self,
f: impl FnOnce(Self) -> Result<Self, Self::Error>
) -> Result<Self, Self::Error>;
fn should_print_region(&self, region: Region<'tcx>) -> bool;
// Provided methods
fn print_value_path(
self,
def_id: DefId,
args: &'tcx [GenericArg<'tcx>]
) -> Result<Self::Path, Self::Error> { ... }
fn in_binder<T>(self, value: &Binder<'tcx, T>) -> Result<Self, Self::Error>
where T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>> { ... }
fn wrap_binder<T, F: FnOnce(&T, Self) -> Result<Self, Error>>(
self,
value: &Binder<'tcx, T>,
f: F
) -> Result<Self, Self::Error>
where T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>> { ... }
fn comma_sep<T>(
self,
elems: impl Iterator<Item = T>
) -> Result<Self, Self::Error>
where T: Print<'tcx, Self, Output = Self, Error = Self::Error> { ... }
fn typed_value(
self,
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
conversion: &str
) -> Result<Self::Const, Self::Error> { ... }
fn reset_type_limit(&mut self) { ... }
fn try_print_visible_def_path(
self,
def_id: DefId
) -> Result<(Self, bool), Self::Error> { ... }
fn force_print_trimmed_def_path(
self,
def_id: DefId
) -> Result<(Self::Path, bool), Self::Error> { ... }
fn try_print_trimmed_def_path(
self,
def_id: DefId
) -> Result<(Self::Path, bool), Self::Error> { ... }
fn try_print_visible_def_path_recur(
self,
def_id: DefId,
callers: &mut Vec<DefId>
) -> Result<(Self, bool), Self::Error> { ... }
fn pretty_path_qualified(
self,
self_ty: Ty<'tcx>,
trait_ref: Option<TraitRef<'tcx>>
) -> Result<Self::Path, Self::Error> { ... }
fn pretty_path_append_impl(
self,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
self_ty: Ty<'tcx>,
trait_ref: Option<TraitRef<'tcx>>
) -> Result<Self::Path, Self::Error> { ... }
fn pretty_print_type(self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> { ... }
fn pretty_print_opaque_impl_type(
self,
def_id: DefId,
args: &'tcx List<GenericArg<'tcx>>
) -> Result<Self::Type, Self::Error> { ... }
fn insert_trait_and_projection(
&mut self,
trait_ref: PolyTraitRef<'tcx>,
proj_ty: Option<(DefId, Binder<'tcx, Term<'tcx>>)>,
traits: &mut FxIndexMap<PolyTraitRef<'tcx>, FxIndexMap<DefId, Binder<'tcx, Term<'tcx>>>>,
fn_traits: &mut FxIndexMap<PolyTraitRef<'tcx>, OpaqueFnEntry<'tcx>>
) { ... }
fn pretty_print_inherent_projection(
self,
alias_ty: &AliasTy<'tcx>
) -> Result<Self::Path, Self::Error> { ... }
fn ty_infer_name(&self, _: TyVid) -> Option<Symbol> { ... }
fn const_infer_name(&self, _: ConstVid<'tcx>) -> Option<Symbol> { ... }
fn pretty_print_dyn_existential(
self,
predicates: &'tcx List<PolyExistentialPredicate<'tcx>>
) -> Result<Self::DynExistential, Self::Error> { ... }
fn pretty_fn_sig(
self,
inputs: &[Ty<'tcx>],
c_variadic: bool,
output: Ty<'tcx>
) -> Result<Self, Self::Error> { ... }
fn pretty_print_const(
self,
ct: Const<'tcx>,
print_ty: bool
) -> Result<Self::Const, Self::Error> { ... }
fn pretty_print_const_scalar(
self,
scalar: Scalar,
ty: Ty<'tcx>
) -> Result<Self::Const, Self::Error> { ... }
fn pretty_print_const_scalar_ptr(
self,
ptr: Pointer,
ty: Ty<'tcx>
) -> Result<Self::Const, Self::Error> { ... }
fn pretty_print_const_scalar_int(
self,
int: ScalarInt,
ty: Ty<'tcx>,
print_ty: bool
) -> Result<Self::Const, Self::Error> { ... }
fn pretty_print_const_pointer<Prov: Provenance>(
self,
_: Pointer<Prov>,
ty: Ty<'tcx>
) -> Result<Self::Const, Self::Error> { ... }
fn pretty_print_byte_str(
self,
byte_str: &'tcx [u8]
) -> Result<Self::Const, Self::Error> { ... }
fn pretty_print_const_valtree(
self,
valtree: ValTree<'tcx>,
ty: Ty<'tcx>,
print_ty: bool
) -> Result<Self::Const, Self::Error> { ... }
fn pretty_closure_as_impl(
self,
closure: ClosureArgs<'tcx>
) -> Result<Self::Const, Self::Error> { ... }
fn should_print_verbose(&self) -> bool { ... }
}
Expand description
Trait for printers that pretty-print using fmt::Write
to the printer.
Required Methods§
sourcefn generic_delimiters(
self,
f: impl FnOnce(Self) -> Result<Self, Self::Error>
) -> Result<Self, Self::Error>
fn generic_delimiters( self, f: impl FnOnce(Self) -> Result<Self, Self::Error> ) -> Result<Self, Self::Error>
Prints <...>
around what f
prints.
sourcefn should_print_region(&self, region: Region<'tcx>) -> bool
fn should_print_region(&self, region: Region<'tcx>) -> bool
Returns true
if the region should be printed in
optional positions, e.g., &'a T
or dyn Tr + 'b
.
This is typically the case for all non-'_
regions.
Provided Methods§
sourcefn print_value_path(
self,
def_id: DefId,
args: &'tcx [GenericArg<'tcx>]
) -> Result<Self::Path, Self::Error>
fn print_value_path( self, def_id: DefId, args: &'tcx [GenericArg<'tcx>] ) -> Result<Self::Path, Self::Error>
Like print_def_path
but for value paths.
fn in_binder<T>(self, value: &Binder<'tcx, T>) -> Result<Self, Self::Error>where T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
fn wrap_binder<T, F: FnOnce(&T, Self) -> Result<Self, Error>>( self, value: &Binder<'tcx, T>, f: F ) -> Result<Self, Self::Error>where T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
sourcefn comma_sep<T>(
self,
elems: impl Iterator<Item = T>
) -> Result<Self, Self::Error>where
T: Print<'tcx, Self, Output = Self, Error = Self::Error>,
fn comma_sep<T>( self, elems: impl Iterator<Item = T> ) -> Result<Self, Self::Error>where T: Print<'tcx, Self, Output = Self, Error = Self::Error>,
Prints comma-separated elements.
sourcefn typed_value(
self,
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
conversion: &str
) -> Result<Self::Const, Self::Error>
fn typed_value( self, f: impl FnOnce(Self) -> Result<Self, Self::Error>, t: impl FnOnce(Self) -> Result<Self, Self::Error>, conversion: &str ) -> Result<Self::Const, Self::Error>
Prints {f: t}
or {f as t}
depending on the cast
argument
fn reset_type_limit(&mut self)
sourcefn try_print_visible_def_path(
self,
def_id: DefId
) -> Result<(Self, bool), Self::Error>
fn try_print_visible_def_path( self, def_id: DefId ) -> Result<(Self, bool), Self::Error>
If possible, this returns a global path resolving to def_id
that is visible
from at least one local module, and returns true
. If the crate defining def_id
is
declared with an extern crate
, the path is guaranteed to use the extern crate
.
fn force_print_trimmed_def_path( self, def_id: DefId ) -> Result<(Self::Path, bool), Self::Error>
sourcefn try_print_trimmed_def_path(
self,
def_id: DefId
) -> Result<(Self::Path, bool), Self::Error>
fn try_print_trimmed_def_path( self, def_id: DefId ) -> Result<(Self::Path, bool), Self::Error>
Try to see if this path can be trimmed to a unique symbol name.
sourcefn try_print_visible_def_path_recur(
self,
def_id: DefId,
callers: &mut Vec<DefId>
) -> Result<(Self, bool), Self::Error>
fn try_print_visible_def_path_recur( self, def_id: DefId, callers: &mut Vec<DefId> ) -> Result<(Self, bool), Self::Error>
Does the work of try_print_visible_def_path
, building the
full definition path recursively before attempting to
post-process it into the valid and visible version that
accounts for re-exports.
This method should only be called by itself or
try_print_visible_def_path
.
callers
is a chain of visible_parent’s leading to def_id
,
to support cycle detection during recursion.
This method returns false if we can’t print the visible path, so
print_def_path
can fall back on the item’s real definition path.
fn pretty_path_qualified( self, self_ty: Ty<'tcx>, trait_ref: Option<TraitRef<'tcx>> ) -> Result<Self::Path, Self::Error>
fn pretty_path_append_impl( self, print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>, self_ty: Ty<'tcx>, trait_ref: Option<TraitRef<'tcx>> ) -> Result<Self::Path, Self::Error>
fn pretty_print_type(self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
fn pretty_print_opaque_impl_type( self, def_id: DefId, args: &'tcx List<GenericArg<'tcx>> ) -> Result<Self::Type, Self::Error>
sourcefn insert_trait_and_projection(
&mut self,
trait_ref: PolyTraitRef<'tcx>,
proj_ty: Option<(DefId, Binder<'tcx, Term<'tcx>>)>,
traits: &mut FxIndexMap<PolyTraitRef<'tcx>, FxIndexMap<DefId, Binder<'tcx, Term<'tcx>>>>,
fn_traits: &mut FxIndexMap<PolyTraitRef<'tcx>, OpaqueFnEntry<'tcx>>
)
fn insert_trait_and_projection( &mut self, trait_ref: PolyTraitRef<'tcx>, proj_ty: Option<(DefId, Binder<'tcx, Term<'tcx>>)>, traits: &mut FxIndexMap<PolyTraitRef<'tcx>, FxIndexMap<DefId, Binder<'tcx, Term<'tcx>>>>, fn_traits: &mut FxIndexMap<PolyTraitRef<'tcx>, OpaqueFnEntry<'tcx>> )
Insert the trait ref and optionally a projection type associated with it into either the traits map or fn_traits map, depending on if the trait is in the Fn* family of traits.
fn pretty_print_inherent_projection( self, alias_ty: &AliasTy<'tcx> ) -> Result<Self::Path, Self::Error>
fn ty_infer_name(&self, _: TyVid) -> Option<Symbol>
fn const_infer_name(&self, _: ConstVid<'tcx>) -> Option<Symbol>
fn pretty_print_dyn_existential( self, predicates: &'tcx List<PolyExistentialPredicate<'tcx>> ) -> Result<Self::DynExistential, Self::Error>
fn pretty_fn_sig( self, inputs: &[Ty<'tcx>], c_variadic: bool, output: Ty<'tcx> ) -> Result<Self, Self::Error>
fn pretty_print_const( self, ct: Const<'tcx>, print_ty: bool ) -> Result<Self::Const, Self::Error>
fn pretty_print_const_scalar( self, scalar: Scalar, ty: Ty<'tcx> ) -> Result<Self::Const, Self::Error>
fn pretty_print_const_scalar_ptr( self, ptr: Pointer, ty: Ty<'tcx> ) -> Result<Self::Const, Self::Error>
fn pretty_print_const_scalar_int( self, int: ScalarInt, ty: Ty<'tcx>, print_ty: bool ) -> Result<Self::Const, Self::Error>
sourcefn pretty_print_const_pointer<Prov: Provenance>(
self,
_: Pointer<Prov>,
ty: Ty<'tcx>
) -> Result<Self::Const, Self::Error>
fn pretty_print_const_pointer<Prov: Provenance>( self, _: Pointer<Prov>, ty: Ty<'tcx> ) -> Result<Self::Const, Self::Error>
This is overridden for MIR printing because we only want to hide alloc ids from users, not from MIR where it is actually useful.