@@ -635,7 +635,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
635635 Ok ( ( ) )
636636 }
637637
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.
639641 pub fn dump_alloc ( & self , id : AllocId ) {
640642 self . dump_allocs ( vec ! [ id] ) ;
641643 }
@@ -674,7 +676,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
674676 }
675677 }
676678
677- trace ! (
679+ eprintln ! (
678680 "{}({} bytes, alignment {}){}" ,
679681 msg,
680682 alloc. size. bytes( ) ,
@@ -695,15 +697,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
695697 write ! ( msg, "└{0:─^1$}┘ " , target, relocation_width as usize ) . unwrap ( ) ;
696698 pos = i + self . pointer_size ( ) ;
697699 }
698- trace ! ( "{}" , msg) ;
700+ eprintln ! ( "{}" , msg) ;
699701 }
700702 }
701703
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.
703707 pub fn dump_allocs ( & self , mut allocs : Vec < AllocId > ) {
704- if !log_enabled ! ( :: log:: Level :: Trace ) {
705- return ;
706- }
707708 allocs. sort ( ) ;
708709 allocs. dedup ( ) ;
709710 let mut allocs_to_print = VecDeque :: from ( allocs) ;
@@ -735,13 +736,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
735736 ) ;
736737 }
737738 Some ( GlobalAlloc :: Function ( func) ) => {
738- trace ! ( "{} {}" , msg, func) ;
739+ eprintln ! ( "{} {}" , msg, func) ;
739740 }
740741 Some ( GlobalAlloc :: Static ( did) ) => {
741- trace ! ( "{} {:?}" , msg, did) ;
742+ eprintln ! ( "{} {:?}" , msg, did) ;
742743 }
743744 None => {
744- trace ! ( "{} (deallocated)" , msg) ;
745+ eprintln ! ( "{} (deallocated)" , msg) ;
745746 }
746747 }
747748 } ,
@@ -751,12 +752,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
751752 }
752753
753754 pub fn leak_report ( & self ) -> usize {
754- trace ! ( "### LEAK REPORT ###" ) ;
755755 let leaks: Vec < _ > = self . alloc_map . filter_map_collect ( |& id, & ( kind, _) | {
756756 if kind. may_leak ( ) { None } else { Some ( id) }
757757 } ) ;
758758 let n = leaks. len ( ) ;
759- self . dump_allocs ( leaks) ;
759+ if n > 0 {
760+ eprintln ! ( "### LEAK REPORT ###" ) ;
761+ self . dump_allocs ( leaks) ;
762+ }
760763 n
761764 }
762765
0 commit comments