@@ -17,9 +17,8 @@ use rustc_middle::mir::interpret::{
17
17
use rustc_middle:: mir:: visit:: Visitor ;
18
18
use rustc_middle:: mir:: MirSource ;
19
19
use rustc_middle:: mir:: * ;
20
- use rustc_middle:: ty:: { self , TyCtxt , TypeFoldable , TypeVisitor } ;
20
+ use rustc_middle:: ty:: { self , TyCtxt } ;
21
21
use rustc_target:: abi:: Size ;
22
- use std:: ops:: ControlFlow ;
23
22
24
23
const INDENT : & str = " " ;
25
24
/// Alignment for lining up comments following MIR statements
@@ -669,6 +668,7 @@ pub fn write_allocations<'tcx>(
669
668
fn alloc_ids_from_alloc ( alloc : & Allocation ) -> impl DoubleEndedIterator < Item = AllocId > + ' _ {
670
669
alloc. relocations ( ) . values ( ) . map ( |id| * id)
671
670
}
671
+
672
672
fn alloc_ids_from_const ( val : ConstValue < ' _ > ) -> impl Iterator < Item = AllocId > + ' _ {
673
673
match val {
674
674
ConstValue :: Scalar ( interpret:: Scalar :: Ptr ( ptr, _size) ) => {
@@ -682,17 +682,29 @@ pub fn write_allocations<'tcx>(
682
682
}
683
683
}
684
684
}
685
+
685
686
struct CollectAllocIds ( BTreeSet < AllocId > ) ;
686
- impl < ' tcx > TypeVisitor < ' tcx > for CollectAllocIds {
687
- fn visit_const ( & mut self , c : ty:: Const < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
687
+
688
+ impl < ' tcx > Visitor < ' tcx > for CollectAllocIds {
689
+ fn visit_const ( & mut self , c : ty:: Const < ' tcx > , _loc : Location ) {
688
690
if let ty:: ConstKind :: Value ( val) = c. val ( ) {
689
691
self . 0 . extend ( alloc_ids_from_const ( val) ) ;
690
692
}
691
- c. super_visit_with ( self )
693
+ }
694
+
695
+ fn visit_constant ( & mut self , c : & Constant < ' tcx > , loc : Location ) {
696
+ match c. literal {
697
+ ConstantKind :: Ty ( c) => self . visit_const ( c, loc) ,
698
+ ConstantKind :: Val ( val, _) => {
699
+ self . 0 . extend ( alloc_ids_from_const ( val) ) ;
700
+ }
701
+ }
692
702
}
693
703
}
704
+
694
705
let mut visitor = CollectAllocIds ( Default :: default ( ) ) ;
695
- body. visit_with ( & mut visitor) ;
706
+ visitor. visit_body ( body) ;
707
+
696
708
// `seen` contains all seen allocations, including the ones we have *not* printed yet.
697
709
// The protocol is to first `insert` into `seen`, and only if that returns `true`
698
710
// then push to `todo`.
0 commit comments