@@ -11,6 +11,7 @@ use rustc_middle::{
1111} ;
1212use rustc_span:: def_id:: DefId ;
1313
14+ #[ derive( Copy , Clone , Debug ) ]
1415enum EdgeKind {
1516 Unwind ,
1617 Normal ,
@@ -54,7 +55,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
5455 ) ;
5556 }
5657
57- fn check_bb ( & self , location : Location , bb : BasicBlock , edge_kind : EdgeKind ) {
58+ fn check_edge ( & self , location : Location , bb : BasicBlock , edge_kind : EdgeKind ) {
5859 if let Some ( bb) = self . body . basic_blocks ( ) . get ( bb) {
5960 let src = self . body . basic_blocks ( ) . get ( location. block ) . unwrap ( ) ;
6061 match ( src. is_cleanup , bb. is_cleanup , edge_kind) {
@@ -68,7 +69,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
6869 _ => {
6970 self . fail (
7071 location,
71- format ! ( "encountered jump that does not respect unwind invariants {:?}" , bb)
72+ format ! (
73+ "{:?} edge to {:?} violates unwind invariants (cleanup {:?} -> {:?})" ,
74+ edge_kind,
75+ bb,
76+ src. is_cleanup,
77+ bb. is_cleanup,
78+ )
7279 )
7380 }
7481 }
@@ -114,7 +121,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
114121 fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , location : Location ) {
115122 match & terminator. kind {
116123 TerminatorKind :: Goto { target } => {
117- self . check_bb ( location, * target, EdgeKind :: Normal ) ;
124+ self . check_edge ( location, * target, EdgeKind :: Normal ) ;
118125 }
119126 TerminatorKind :: SwitchInt { targets, values, .. } => {
120127 if targets. len ( ) != values. len ( ) + 1 {
@@ -128,19 +135,19 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
128135 ) ;
129136 }
130137 for target in targets {
131- self . check_bb ( location, * target, EdgeKind :: Normal ) ;
138+ self . check_edge ( location, * target, EdgeKind :: Normal ) ;
132139 }
133140 }
134141 TerminatorKind :: Drop { target, unwind, .. } => {
135- self . check_bb ( location, * target, EdgeKind :: Normal ) ;
142+ self . check_edge ( location, * target, EdgeKind :: Normal ) ;
136143 if let Some ( unwind) = unwind {
137- self . check_bb ( location, * unwind, EdgeKind :: Unwind ) ;
144+ self . check_edge ( location, * unwind, EdgeKind :: Unwind ) ;
138145 }
139146 }
140147 TerminatorKind :: DropAndReplace { target, unwind, .. } => {
141- self . check_bb ( location, * target, EdgeKind :: Normal ) ;
148+ self . check_edge ( location, * target, EdgeKind :: Normal ) ;
142149 if let Some ( unwind) = unwind {
143- self . check_bb ( location, * unwind, EdgeKind :: Unwind ) ;
150+ self . check_edge ( location, * unwind, EdgeKind :: Unwind ) ;
144151 }
145152 }
146153 TerminatorKind :: Call { func, destination, cleanup, .. } => {
@@ -153,10 +160,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
153160 ) ,
154161 }
155162 if let Some ( ( _, target) ) = destination {
156- self . check_bb ( location, * target, EdgeKind :: Normal ) ;
163+ self . check_edge ( location, * target, EdgeKind :: Normal ) ;
157164 }
158165 if let Some ( cleanup) = cleanup {
159- self . check_bb ( location, * cleanup, EdgeKind :: Unwind ) ;
166+ self . check_edge ( location, * cleanup, EdgeKind :: Unwind ) ;
160167 }
161168 }
162169 TerminatorKind :: Assert { cond, target, cleanup, .. } => {
@@ -170,30 +177,30 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
170177 ) ,
171178 ) ;
172179 }
173- self . check_bb ( location, * target, EdgeKind :: Normal ) ;
180+ self . check_edge ( location, * target, EdgeKind :: Normal ) ;
174181 if let Some ( cleanup) = cleanup {
175- self . check_bb ( location, * cleanup, EdgeKind :: Unwind ) ;
182+ self . check_edge ( location, * cleanup, EdgeKind :: Unwind ) ;
176183 }
177184 }
178185 TerminatorKind :: Yield { resume, drop, .. } => {
179- self . check_bb ( location, * resume, EdgeKind :: Normal ) ;
186+ self . check_edge ( location, * resume, EdgeKind :: Normal ) ;
180187 if let Some ( drop) = drop {
181- self . check_bb ( location, * drop, EdgeKind :: Normal ) ;
188+ self . check_edge ( location, * drop, EdgeKind :: Normal ) ;
182189 }
183190 }
184191 TerminatorKind :: FalseEdge { real_target, imaginary_target } => {
185- self . check_bb ( location, * real_target, EdgeKind :: Normal ) ;
186- self . check_bb ( location, * imaginary_target, EdgeKind :: Normal ) ;
192+ self . check_edge ( location, * real_target, EdgeKind :: Normal ) ;
193+ self . check_edge ( location, * imaginary_target, EdgeKind :: Normal ) ;
187194 }
188195 TerminatorKind :: FalseUnwind { real_target, unwind } => {
189- self . check_bb ( location, * real_target, EdgeKind :: Normal ) ;
196+ self . check_edge ( location, * real_target, EdgeKind :: Normal ) ;
190197 if let Some ( unwind) = unwind {
191- self . check_bb ( location, * unwind, EdgeKind :: Unwind ) ;
198+ self . check_edge ( location, * unwind, EdgeKind :: Unwind ) ;
192199 }
193200 }
194201 TerminatorKind :: InlineAsm { destination, .. } => {
195202 if let Some ( destination) = destination {
196- self . check_bb ( location, * destination, EdgeKind :: Normal ) ;
203+ self . check_edge ( location, * destination, EdgeKind :: Normal ) ;
197204 }
198205 }
199206 // Nothing to validate for these.
0 commit comments