Address review comments

This commit is contained in:
Oliver Scherer 2020-07-29 11:37:33 +02:00
parent 7d67a1b871
commit b81d164f61
2 changed files with 46 additions and 44 deletions

View File

@ -84,13 +84,11 @@ impl std::ops::Deref for CrateMetadataRef<'_> {
struct CrateDump<'a>(&'a CStore);
fn crate_dump(cstore: &'a CStore) -> impl std::fmt::Debug + 'a {
CrateDump(cstore)
}
impl<'a> std::fmt::Debug for CrateDump<'a> {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(fmt, "resolved crates:")?;
// `iter_crate_data` does not allow returning values. Thus we use a mutable variable here
// that aggregates the value (and any errors that could happen).
let mut res = Ok(());
self.0.iter_crate_data(|cnum, data| {
res = res.and(
@ -878,7 +876,7 @@ impl<'a> CrateLoader<'a> {
self.inject_allocator_crate(krate);
self.inject_panic_runtime(krate);
info!("{:?}", crate_dump(&self.cstore));
info!("{:?}", CrateDump(&self.cstore));
self.report_unused_deps(krate);
}

View File

@ -1905,49 +1905,53 @@ macro_rules! sty_debug_print {
impl<'tcx> TyCtxt<'tcx> {
pub fn debug_stats(self) -> impl std::fmt::Debug + 'tcx {
struct DebugStats<'tcx>(TyCtxt<'tcx>);
impl std::fmt::Debug for DebugStats<'tcx> {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
sty_debug_print!(
fmt,
self.0,
Adt,
Array,
Slice,
RawPtr,
Ref,
FnDef,
FnPtr,
Placeholder,
Generator,
GeneratorWitness,
Dynamic,
Closure,
Tuple,
Bound,
Param,
Infer,
Projection,
Opaque,
Foreign
)?;
writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?;
writeln!(fmt, "Region interner: #{}", self.0.interners.region.len())?;
writeln!(fmt, "Stability interner: #{}", self.0.stability_interner.len())?;
writeln!(
fmt,
"Const Stability interner: #{}",
self.0.const_stability_interner.len()
)?;
writeln!(fmt, "Allocation interner: #{}", self.0.allocation_interner.len())?;
writeln!(fmt, "Layout interner: #{}", self.0.layout_interner.len())?;
Ok(())
}
}
DebugStats(self)
}
}
struct DebugStats<'tcx>(TyCtxt<'tcx>);
impl std::fmt::Debug for DebugStats<'tcx> {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
sty_debug_print!(
fmt,
self.0,
Adt,
Array,
Slice,
RawPtr,
Ref,
FnDef,
FnPtr,
Placeholder,
Generator,
GeneratorWitness,
Dynamic,
Closure,
Tuple,
Bound,
Param,
Infer,
Projection,
Opaque,
Foreign
)?;
writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?;
writeln!(fmt, "Region interner: #{}", self.0.interners.region.len())?;
writeln!(fmt, "Stability interner: #{}", self.0.stability_interner.len())?;
writeln!(fmt, "Const Stability interner: #{}", self.0.const_stability_interner.len())?;
writeln!(fmt, "Allocation interner: #{}", self.0.allocation_interner.len())?;
writeln!(fmt, "Layout interner: #{}", self.0.layout_interner.len())?;
Ok(())
}
}
/// An entry in an interner.
struct Interned<'tcx, T: ?Sized>(&'tcx T);