@@ -520,12 +520,9 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> {
520
520
} => {
521
521
let vals: Vec < String > =
522
522
targets. iter ( ) . map ( |( c, _) | c. to_string ( ) ) . collect ( ) ;
523
- let discr_span = mir. match_span_map . get ( & self . source_info . span ) . cloned ( )
524
- . unwrap_or ( self . source_info . span ) ;
525
523
json ! ( {
526
524
"kind" : "SwitchInt" ,
527
525
"discr" : discr. to_json( mir) ,
528
- "discr_span" : discr_span. to_json( mir) ,
529
526
"values" : vals,
530
527
"targets" : targets. all_targets( ) . iter( ) . map( |x| x. to_json( mir) )
531
528
. collect:: <Vec <_>>( ) ,
@@ -1081,7 +1078,6 @@ fn emit_fn<'tcx>(
1081
1078
used : ms. used ,
1082
1079
state : ms. state ,
1083
1080
tys : ms. tys ,
1084
- match_span_map : ms. match_span_map ,
1085
1081
allocs : ms. allocs ,
1086
1082
export_style : ms. export_style ,
1087
1083
} ;
@@ -1226,7 +1222,6 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result<O>>(
1226
1222
used : & mut used,
1227
1223
state : & state,
1228
1224
tys : & mut tys,
1229
- match_span_map : & get_match_spans ( ) ,
1230
1225
allocs : & mut allocs,
1231
1226
export_style : export_style,
1232
1227
} ;
@@ -1350,86 +1345,3 @@ pub fn inject_attrs<'tcx>(krate: &mut Crate) {
1350
1345
krate. attrs . push ( make_attr ( "feature" , "register_tool" ) ) ;
1351
1346
krate. attrs . push ( make_attr ( "register_tool" , "crux" ) ) ;
1352
1347
}
1353
-
1354
- #[ derive( Default ) ]
1355
- struct GatherMatchSpans {
1356
- match_span_map : HashMap < Span , Span > ,
1357
- cur_match_discr_span : Option < Span > ,
1358
- }
1359
-
1360
- impl GatherMatchSpans {
1361
- fn with_cur_match_discr_span ( & mut self , val : Option < Span > , f : impl FnOnce ( & mut Self ) ) {
1362
- let old = mem:: replace ( & mut self . cur_match_discr_span , val) ;
1363
- f ( self ) ;
1364
- self . cur_match_discr_span = old;
1365
- }
1366
- }
1367
-
1368
- impl < ' a > visit:: Visitor < ' a > for GatherMatchSpans {
1369
- fn visit_expr ( & mut self , e : & ast:: Expr ) {
1370
- match e. kind {
1371
- ast:: ExprKind :: Match ( ref discr, ref arms, _kind) => {
1372
- self . visit_expr ( discr) ;
1373
-
1374
- self . with_cur_match_discr_span ( Some ( discr. span ) , |self_| {
1375
- for arm in arms {
1376
- self_. visit_arm ( arm) ;
1377
- }
1378
- } ) ;
1379
- } ,
1380
- _ => visit:: walk_expr ( self , e) ,
1381
- }
1382
- }
1383
-
1384
- fn visit_arm ( & mut self , a : & ast:: Arm ) {
1385
- // The discr span should be available in the patterns of the arm, but not its guard or body
1386
- // expressions.
1387
- self . visit_pat ( & a. pat ) ;
1388
- self . with_cur_match_discr_span ( None , |self_| {
1389
- if let Some ( ref e) = a. guard {
1390
- self_. visit_expr ( e) ;
1391
- }
1392
- if let Some ( ref e) = a. body {
1393
- self_. visit_expr ( e) ;
1394
- }
1395
- } ) ;
1396
- }
1397
-
1398
- fn visit_pat ( & mut self , p : & ast:: Pat ) {
1399
- if let Some ( span) = self . cur_match_discr_span {
1400
- self . match_span_map . insert ( p. span , span) ;
1401
- }
1402
- visit:: walk_pat ( self , p)
1403
- }
1404
- }
1405
-
1406
- thread_local ! {
1407
- /// See documentation on `MirState::match_span_map` for info.
1408
- ///
1409
- /// The handling of the `match_span_map` is a little tricky. The map must be constructed
1410
- /// during `rustc_driver::Callbacks::after_expansion`, then used during `after_analysis`. We'd
1411
- /// like to pass the map from one callback to the other through our struct that implements
1412
- /// `Callbacks`, but this is forbidden: the callbacks must implement `Send`, while `Span` is
1413
- /// `!Send` and `!Sync`. Instead, we pass it through this thread-local variable, and just hope
1414
- /// that `after_expansion` and `after_analysis` get called on the same thread. It seems likely
1415
- /// that they will be, since both get access to data structures that contain spans, and the
1416
- /// span interning table is also thread-local (likely this is why spans are `!Sync`).
1417
- static MATCH_SPAN_MAP : RefCell <Option <Rc <HashMap <Span , Span >>>> = RefCell :: default ( )
1418
- }
1419
-
1420
- pub fn gather_match_spans < ' tcx > ( tcx : TyCtxt < ' tcx > ) {
1421
- let resolver = tcx. resolver_for_lowering ( ) ;
1422
- let krate = & resolver. borrow ( ) . 1 ;
1423
- let mut v = GatherMatchSpans :: default ( ) ;
1424
- visit:: walk_crate ( & mut v, krate) ;
1425
- MATCH_SPAN_MAP . with ( |m| m. replace ( Some ( Rc :: new ( v. match_span_map ) ) ) ) ;
1426
- }
1427
-
1428
- fn get_match_spans ( ) -> Rc < HashMap < Span , Span > > {
1429
- MATCH_SPAN_MAP . with ( |m| {
1430
- match * m. borrow ( ) {
1431
- Some ( ref rc) => rc. clone ( ) ,
1432
- None => panic ! ( "MATCH_SPAN_MAP is uninitialized on this thread" ) ,
1433
- }
1434
- } )
1435
- }
0 commit comments