1
Fork 0

All verbosity checks in PrettyPrinter now go through PrettyPrinter::should_print_verbose

This commit is contained in:
Sarthak Singh 2022-10-30 17:38:49 +05:30
parent b03502b35d
commit 8609364480
3 changed files with 35 additions and 26 deletions

View file

@ -4,7 +4,7 @@ use rustc_hir::definitions::DisambiguatedDefPathData;
use rustc_middle::mir::interpret::{Allocation, ConstAllocation};
use rustc_middle::ty::{
self,
print::{with_no_verbose_constants, PrettyPrinter, Print, Printer},
print::{PrettyPrinter, Print, Printer},
subst::{GenericArg, GenericArgKind},
Ty, TyCtxt,
};
@ -179,6 +179,11 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
Ok(self)
}
fn should_print_verbose(&self) -> bool {
// `std::any::type_name` should never print verbose type names
false
}
}
impl Write for AbsolutePathPrinter<'_> {
@ -190,9 +195,7 @@ impl Write for AbsolutePathPrinter<'_> {
/// Directly returns an `Allocation` containing an absolute path representation of the given type.
pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> {
let path = with_no_verbose_constants!(
AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path
);
let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path;
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
tcx.intern_const_alloc(alloc)
}