rustc_middle::ty::print

Trait PrettyPrinter

Source
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_pred: PolyTraitPredicate<'tcx>, proj_ty: Option<(DefId, Binder<'tcx, Term<'tcx>>)>, traits: &mut FxIndexMap<PolyTraitPredicate<'tcx>, FxIndexMap<DefId, Binder<'tcx, Term<'tcx>>>>, fn_traits: &mut FxIndexMap<(Binder<'tcx, &'tcx List<Ty<'tcx>>>, bool), 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§

Source

fn generic_delimiters( &mut self, f: impl FnOnce(&mut Self) -> Result<(), PrintError>, ) -> Result<(), PrintError>

Prints <...> around what f prints.

Source

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§

Source

fn print_value_path( &mut self, def_id: DefId, args: &'tcx [GenericArg<'tcx>], ) -> Result<(), PrintError>

Like print_def_path but for value paths.

Source

fn in_binder<T>(&mut self, value: &Binder<'tcx, T>) -> Result<(), PrintError>
where T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,

Source

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>>,

Source

fn comma_sep<T>( &mut self, elems: impl Iterator<Item = T>, ) -> Result<(), PrintError>
where T: Print<'tcx, Self>,

Prints comma-separated elements.

Source

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

Source

fn parenthesized( &mut self, f: impl FnOnce(&mut Self) -> Result<(), PrintError>, ) -> Result<(), PrintError>

Prints (...) around what f prints.

Source

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.

Source

fn reset_type_limit(&mut self)

Source

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.

Source

fn force_print_trimmed_def_path( &mut self, def_id: DefId, ) -> Result<bool, PrintError>

Source

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.

Source

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.

Source

fn pretty_path_qualified( &mut self, self_ty: Ty<'tcx>, trait_ref: Option<TraitRef<'tcx>>, ) -> Result<(), PrintError>

Source

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>

Source

fn pretty_print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError>

Source

fn pretty_print_opaque_impl_type( &mut self, def_id: DefId, args: GenericArgsRef<'tcx>, ) -> Result<(), PrintError>

Source

fn insert_trait_and_projection( &mut self, trait_pred: PolyTraitPredicate<'tcx>, proj_ty: Option<(DefId, Binder<'tcx, Term<'tcx>>)>, traits: &mut FxIndexMap<PolyTraitPredicate<'tcx>, FxIndexMap<DefId, Binder<'tcx, Term<'tcx>>>>, fn_traits: &mut FxIndexMap<(Binder<'tcx, &'tcx List<Ty<'tcx>>>, bool), 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.

Source

fn pretty_print_inherent_projection( &mut self, alias_ty: AliasTerm<'tcx>, ) -> Result<(), PrintError>

Source

fn ty_infer_name(&self, _: TyVid) -> Option<Symbol>

Source

fn const_infer_name(&self, _: ConstVid) -> Option<Symbol>

Source

fn pretty_print_dyn_existential( &mut self, predicates: &'tcx List<PolyExistentialPredicate<'tcx>>, ) -> Result<(), PrintError>

Source

fn pretty_fn_sig( &mut self, inputs: &[Ty<'tcx>], c_variadic: bool, output: Ty<'tcx>, ) -> Result<(), PrintError>

Source

fn pretty_print_const( &mut self, ct: Const<'tcx>, print_ty: bool, ) -> Result<(), PrintError>

Source

fn pretty_print_const_expr( &mut self, expr: Expr<'tcx>, print_ty: bool, ) -> Result<(), PrintError>

Source

fn pretty_print_const_scalar( &mut self, scalar: Scalar, ty: Ty<'tcx>, ) -> Result<(), PrintError>

Source

fn pretty_print_const_scalar_ptr( &mut self, ptr: Pointer, ty: Ty<'tcx>, ) -> Result<(), PrintError>

Source

fn pretty_print_const_scalar_int( &mut self, int: ScalarInt, ty: Ty<'tcx>, print_ty: bool, ) -> Result<(), PrintError>

Source

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.

Source

fn pretty_print_byte_str( &mut self, byte_str: &'tcx [u8], ) -> Result<(), PrintError>

Source

fn pretty_print_const_valtree( &mut self, valtree: ValTree<'tcx>, ty: Ty<'tcx>, print_ty: bool, ) -> Result<(), PrintError>

Source

fn pretty_closure_as_impl( &mut self, closure: ClosureArgs<TyCtxt<'tcx>>, ) -> Result<(), PrintError>

Source

fn pretty_print_bound_constness( &mut self, constness: BoundConstness, ) -> Result<(), PrintError>

Source

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.

Implementors§

Source§

impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx>