pub trait PrettyPrinter<'tcx>: Printer<'tcx> + Write {
Show 35 methods
// Required methods
fn generic_delimiters(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
) -> Result<(), PrintError>;
fn should_print_region(&self, region: Region<'tcx>) -> bool;
// Provided methods
fn print_value_path(
&mut self,
def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
) -> Result<(), PrintError> { ... }
fn in_binder<T>(
&mut self,
value: &Binder<'tcx, T>,
) -> Result<(), PrintError>
where T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>> { ... }
fn wrap_binder<T, F: FnOnce(&T, &mut Self) -> Result<(), Error>>(
&mut self,
value: &Binder<'tcx, T>,
f: F,
) -> Result<(), PrintError>
where T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>> { ... }
fn comma_sep<T>(
&mut self,
elems: impl Iterator<Item = T>,
) -> Result<(), PrintError>
where T: Print<'tcx, Self> { ... }
fn typed_value(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
t: impl FnOnce(&mut Self) -> Result<(), PrintError>,
conversion: &str,
) -> Result<(), PrintError> { ... }
fn parenthesized(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
) -> Result<(), PrintError> { ... }
fn maybe_parenthesized(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
parenthesized: bool,
) -> Result<(), PrintError> { ... }
fn reset_type_limit(&mut self) { ... }
fn try_print_visible_def_path(
&mut self,
def_id: DefId,
) -> Result<bool, PrintError> { ... }
fn force_print_trimmed_def_path(
&mut self,
def_id: DefId,
) -> Result<bool, PrintError> { ... }
fn try_print_trimmed_def_path(
&mut self,
def_id: DefId,
) -> Result<bool, PrintError> { ... }
fn try_print_visible_def_path_recur(
&mut self,
def_id: DefId,
callers: &mut Vec<DefId>,
) -> Result<bool, PrintError> { ... }
fn pretty_path_qualified(
&mut self,
self_ty: Ty<'tcx>,
trait_ref: Option<TraitRef<'tcx>>,
) -> Result<(), PrintError> { ... }
fn pretty_path_append_impl(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
self_ty: Ty<'tcx>,
trait_ref: Option<TraitRef<'tcx>>,
) -> Result<(), PrintError> { ... }
fn pretty_print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> { ... }
fn pretty_print_opaque_impl_type(
&mut self,
def_id: DefId,
args: GenericArgsRef<'tcx>,
) -> Result<(), PrintError> { ... }
fn insert_trait_and_projection(
&mut self,
trait_ref: PolyTraitRef<'tcx>,
polarity: PredicatePolarity,
proj_ty: Option<(DefId, Binder<'tcx, Term<'tcx>>)>,
traits: &mut FxIndexMap<(PolyTraitRef<'tcx>, PredicatePolarity), FxIndexMap<DefId, Binder<'tcx, Term<'tcx>>>>,
fn_traits: &mut FxIndexMap<PolyTraitRef<'tcx>, OpaqueFnEntry<'tcx>>,
) { ... }
fn pretty_print_inherent_projection(
&mut self,
alias_ty: AliasTerm<'tcx>,
) -> Result<(), PrintError> { ... }
fn ty_infer_name(&self, _: TyVid) -> Option<Symbol> { ... }
fn const_infer_name(&self, _: ConstVid) -> Option<Symbol> { ... }
fn pretty_print_dyn_existential(
&mut self,
predicates: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> Result<(), PrintError> { ... }
fn pretty_fn_sig(
&mut self,
inputs: &[Ty<'tcx>],
c_variadic: bool,
output: Ty<'tcx>,
) -> Result<(), PrintError> { ... }
fn pretty_print_const(
&mut self,
ct: Const<'tcx>,
print_ty: bool,
) -> Result<(), PrintError> { ... }
fn pretty_print_const_expr(
&mut self,
expr: Expr<'tcx>,
print_ty: bool,
) -> Result<(), PrintError> { ... }
fn pretty_print_const_scalar(
&mut self,
scalar: Scalar,
ty: Ty<'tcx>,
) -> Result<(), PrintError> { ... }
fn pretty_print_const_scalar_ptr(
&mut self,
ptr: Pointer,
ty: Ty<'tcx>,
) -> Result<(), PrintError> { ... }
fn pretty_print_const_scalar_int(
&mut self,
int: ScalarInt,
ty: Ty<'tcx>,
print_ty: bool,
) -> Result<(), PrintError> { ... }
fn pretty_print_const_pointer<Prov: Provenance>(
&mut self,
_: Pointer<Prov>,
ty: Ty<'tcx>,
) -> Result<(), PrintError> { ... }
fn pretty_print_byte_str(
&mut self,
byte_str: &'tcx [u8],
) -> Result<(), PrintError> { ... }
fn pretty_print_const_valtree(
&mut self,
valtree: ValTree<'tcx>,
ty: Ty<'tcx>,
print_ty: bool,
) -> Result<(), PrintError> { ... }
fn pretty_closure_as_impl(
&mut self,
closure: ClosureArgs<TyCtxt<'tcx>>,
) -> Result<(), PrintError> { ... }
fn pretty_print_bound_constness(
&mut self,
constness: BoundConstness,
) -> Result<(), PrintError> { ... }
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(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
) -> Result<(), PrintError>
fn generic_delimiters( &mut self, f: impl FnOnce(&mut Self) -> Result<(), PrintError>, ) -> Result<(), PrintError>
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(
&mut self,
def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
) -> Result<(), PrintError>
fn print_value_path( &mut self, def_id: DefId, args: &'tcx [GenericArg<'tcx>], ) -> Result<(), PrintError>
Like print_def_path
but for value paths.
fn in_binder<T>(&mut self, value: &Binder<'tcx, T>) -> Result<(), PrintError>
fn wrap_binder<T, F: FnOnce(&T, &mut Self) -> Result<(), Error>>( &mut self, value: &Binder<'tcx, T>, f: F, ) -> Result<(), PrintError>
sourcefn comma_sep<T>(
&mut self,
elems: impl Iterator<Item = T>,
) -> Result<(), PrintError>where
T: Print<'tcx, Self>,
fn comma_sep<T>(
&mut self,
elems: impl Iterator<Item = T>,
) -> Result<(), PrintError>where
T: Print<'tcx, Self>,
Prints comma-separated elements.
sourcefn typed_value(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
t: impl FnOnce(&mut Self) -> Result<(), PrintError>,
conversion: &str,
) -> Result<(), PrintError>
fn typed_value( &mut self, f: impl FnOnce(&mut Self) -> Result<(), PrintError>, t: impl FnOnce(&mut Self) -> Result<(), PrintError>, conversion: &str, ) -> Result<(), PrintError>
Prints {f: t}
or {f as t}
depending on the cast
argument
sourcefn parenthesized(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
) -> Result<(), PrintError>
fn parenthesized( &mut self, f: impl FnOnce(&mut Self) -> Result<(), PrintError>, ) -> Result<(), PrintError>
Prints (...)
around what f
prints.
sourcefn maybe_parenthesized(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
parenthesized: bool,
) -> Result<(), PrintError>
fn maybe_parenthesized( &mut self, f: impl FnOnce(&mut Self) -> Result<(), PrintError>, parenthesized: bool, ) -> Result<(), PrintError>
Prints (...)
around what f
prints if parenthesized
is true, otherwise just prints f
.
fn reset_type_limit(&mut self)
sourcefn try_print_visible_def_path(
&mut self,
def_id: DefId,
) -> Result<bool, PrintError>
fn try_print_visible_def_path( &mut self, def_id: DefId, ) -> Result<bool, PrintError>
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( &mut self, def_id: DefId, ) -> Result<bool, PrintError>
sourcefn try_print_trimmed_def_path(
&mut self,
def_id: DefId,
) -> Result<bool, PrintError>
fn try_print_trimmed_def_path( &mut self, def_id: DefId, ) -> Result<bool, PrintError>
Try to see if this path can be trimmed to a unique symbol name.
sourcefn try_print_visible_def_path_recur(
&mut self,
def_id: DefId,
callers: &mut Vec<DefId>,
) -> Result<bool, PrintError>
fn try_print_visible_def_path_recur( &mut self, def_id: DefId, callers: &mut Vec<DefId>, ) -> Result<bool, PrintError>
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( &mut self, self_ty: Ty<'tcx>, trait_ref: Option<TraitRef<'tcx>>, ) -> Result<(), PrintError>
fn pretty_path_append_impl( &mut self, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, self_ty: Ty<'tcx>, trait_ref: Option<TraitRef<'tcx>>, ) -> Result<(), PrintError>
fn pretty_print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError>
fn pretty_print_opaque_impl_type( &mut self, def_id: DefId, args: GenericArgsRef<'tcx>, ) -> Result<(), PrintError>
sourcefn insert_trait_and_projection(
&mut self,
trait_ref: PolyTraitRef<'tcx>,
polarity: PredicatePolarity,
proj_ty: Option<(DefId, Binder<'tcx, Term<'tcx>>)>,
traits: &mut FxIndexMap<(PolyTraitRef<'tcx>, PredicatePolarity), 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>, polarity: PredicatePolarity, proj_ty: Option<(DefId, Binder<'tcx, Term<'tcx>>)>, traits: &mut FxIndexMap<(PolyTraitRef<'tcx>, PredicatePolarity), 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( &mut self, alias_ty: AliasTerm<'tcx>, ) -> Result<(), PrintError>
fn ty_infer_name(&self, _: TyVid) -> Option<Symbol>
fn const_infer_name(&self, _: ConstVid) -> Option<Symbol>
fn pretty_print_dyn_existential( &mut self, predicates: &'tcx List<PolyExistentialPredicate<'tcx>>, ) -> Result<(), PrintError>
fn pretty_fn_sig( &mut self, inputs: &[Ty<'tcx>], c_variadic: bool, output: Ty<'tcx>, ) -> Result<(), PrintError>
fn pretty_print_const( &mut self, ct: Const<'tcx>, print_ty: bool, ) -> Result<(), PrintError>
fn pretty_print_const_expr( &mut self, expr: Expr<'tcx>, print_ty: bool, ) -> Result<(), PrintError>
fn pretty_print_const_scalar( &mut self, scalar: Scalar, ty: Ty<'tcx>, ) -> Result<(), PrintError>
fn pretty_print_const_scalar_ptr( &mut self, ptr: Pointer, ty: Ty<'tcx>, ) -> Result<(), PrintError>
fn pretty_print_const_scalar_int( &mut self, int: ScalarInt, ty: Ty<'tcx>, print_ty: bool, ) -> Result<(), PrintError>
sourcefn pretty_print_const_pointer<Prov: Provenance>(
&mut self,
_: Pointer<Prov>,
ty: Ty<'tcx>,
) -> Result<(), PrintError>
fn pretty_print_const_pointer<Prov: Provenance>( &mut self, _: Pointer<Prov>, ty: Ty<'tcx>, ) -> Result<(), PrintError>
This is overridden for MIR printing because we only want to hide alloc ids from users, not from MIR where it is actually useful.
fn pretty_print_byte_str( &mut self, byte_str: &'tcx [u8], ) -> Result<(), PrintError>
fn pretty_print_const_valtree( &mut self, valtree: ValTree<'tcx>, ty: Ty<'tcx>, print_ty: bool, ) -> Result<(), PrintError>
fn pretty_closure_as_impl( &mut self, closure: ClosureArgs<TyCtxt<'tcx>>, ) -> Result<(), PrintError>
fn pretty_print_bound_constness( &mut self, constness: BoundConstness, ) -> Result<(), PrintError>
fn should_print_verbose(&self) -> bool
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.