@@ -635,7 +635,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
635
635
Ok ( ( ) )
636
636
}
637
637
638
- /// For debugging, print an allocation and all allocations it points to, recursively.
638
+ /// Print an allocation and all allocations it points to, recursively.
639
+ /// This prints directly to stderr, ignoring RUSTC_LOG! It is up to the caller to
640
+ /// control for this.
639
641
pub fn dump_alloc ( & self , id : AllocId ) {
640
642
self . dump_allocs ( vec ! [ id] ) ;
641
643
}
@@ -674,7 +676,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
674
676
}
675
677
}
676
678
677
- trace ! (
679
+ eprintln ! (
678
680
"{}({} bytes, alignment {}){}" ,
679
681
msg,
680
682
alloc. size. bytes( ) ,
@@ -695,15 +697,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
695
697
write ! ( msg, "└{0:─^1$}┘ " , target, relocation_width as usize ) . unwrap ( ) ;
696
698
pos = i + self . pointer_size ( ) ;
697
699
}
698
- trace ! ( "{}" , msg) ;
700
+ eprintln ! ( "{}" , msg) ;
699
701
}
700
702
}
701
703
702
- /// For debugging, print a list of allocations and all allocations they point to, recursively.
704
+ /// Print a list of allocations and all allocations they point to, recursively.
705
+ /// This prints directly to stderr, ignoring RUSTC_LOG! It is up to the caller to
706
+ /// control for this.
703
707
pub fn dump_allocs ( & self , mut allocs : Vec < AllocId > ) {
704
- if !log_enabled ! ( :: log:: Level :: Trace ) {
705
- return ;
706
- }
707
708
allocs. sort ( ) ;
708
709
allocs. dedup ( ) ;
709
710
let mut allocs_to_print = VecDeque :: from ( allocs) ;
@@ -735,13 +736,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
735
736
) ;
736
737
}
737
738
Some ( GlobalAlloc :: Function ( func) ) => {
738
- trace ! ( "{} {}" , msg, func) ;
739
+ eprintln ! ( "{} {}" , msg, func) ;
739
740
}
740
741
Some ( GlobalAlloc :: Static ( did) ) => {
741
- trace ! ( "{} {:?}" , msg, did) ;
742
+ eprintln ! ( "{} {:?}" , msg, did) ;
742
743
}
743
744
None => {
744
- trace ! ( "{} (deallocated)" , msg) ;
745
+ eprintln ! ( "{} (deallocated)" , msg) ;
745
746
}
746
747
}
747
748
} ,
@@ -751,12 +752,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
751
752
}
752
753
753
754
pub fn leak_report ( & self ) -> usize {
754
- trace ! ( "### LEAK REPORT ###" ) ;
755
755
let leaks: Vec < _ > = self . alloc_map . filter_map_collect ( |& id, & ( kind, _) | {
756
756
if kind. may_leak ( ) { None } else { Some ( id) }
757
757
} ) ;
758
758
let n = leaks. len ( ) ;
759
- self . dump_allocs ( leaks) ;
759
+ if n > 0 {
760
+ eprintln ! ( "### LEAK REPORT ###" ) ;
761
+ self . dump_allocs ( leaks) ;
762
+ }
760
763
n
761
764
}
762
765
0 commit comments