@@ -353,14 +353,22 @@ where
353
353
for statement in & data. statements {
354
354
extra_data ( PassWhere :: BeforeLocation ( current_location) , w) ?;
355
355
let indented_body = format ! ( "{0}{0}{1:?};" , INDENT , statement) ;
356
- writeln ! (
357
- w,
358
- "{:A$} // {}{}" ,
359
- indented_body,
360
- if tcx. sess. verbose( ) { format!( "{:?}: " , current_location) } else { String :: new( ) } ,
361
- comment( tcx, statement. source_info, body. span) ,
362
- A = ALIGN ,
363
- ) ?;
356
+ if tcx. sess . opts . unstable_opts . mir_include_spans {
357
+ writeln ! (
358
+ w,
359
+ "{:A$} // {}{}" ,
360
+ indented_body,
361
+ if tcx. sess. verbose( ) {
362
+ format!( "{:?}: " , current_location)
363
+ } else {
364
+ String :: new( )
365
+ } ,
366
+ comment( tcx, statement. source_info) ,
367
+ A = ALIGN ,
368
+ ) ?;
369
+ } else {
370
+ writeln ! ( w, "{}" , indented_body) ?;
371
+ }
364
372
365
373
write_extra ( tcx, w, |visitor| {
366
374
visitor. visit_statement ( statement, current_location) ;
@@ -374,14 +382,18 @@ where
374
382
// Terminator at the bottom.
375
383
extra_data ( PassWhere :: BeforeLocation ( current_location) , w) ?;
376
384
let indented_terminator = format ! ( "{0}{0}{1:?};" , INDENT , data. terminator( ) . kind) ;
377
- writeln ! (
378
- w,
379
- "{:A$} // {}{}" ,
380
- indented_terminator,
381
- if tcx. sess. verbose( ) { format!( "{:?}: " , current_location) } else { String :: new( ) } ,
382
- comment( tcx, data. terminator( ) . source_info, body. span) ,
383
- A = ALIGN ,
384
- ) ?;
385
+ if tcx. sess . opts . unstable_opts . mir_include_spans {
386
+ writeln ! (
387
+ w,
388
+ "{:A$} // {}{}" ,
389
+ indented_terminator,
390
+ if tcx. sess. verbose( ) { format!( "{:?}: " , current_location) } else { String :: new( ) } ,
391
+ comment( tcx, data. terminator( ) . source_info) ,
392
+ A = ALIGN ,
393
+ ) ?;
394
+ } else {
395
+ writeln ! ( w, "{}" , indented_terminator) ?;
396
+ }
385
397
386
398
write_extra ( tcx, w, |visitor| {
387
399
visitor. visit_terminator ( data. terminator ( ) , current_location) ;
@@ -400,10 +412,12 @@ fn write_extra<'tcx, F>(tcx: TyCtxt<'tcx>, write: &mut dyn Write, mut visit_op:
400
412
where
401
413
F : FnMut ( & mut ExtraComments < ' tcx > ) ,
402
414
{
403
- let mut extra_comments = ExtraComments { tcx, comments : vec ! [ ] } ;
404
- visit_op ( & mut extra_comments) ;
405
- for comment in extra_comments. comments {
406
- writeln ! ( write, "{:A$} // {}" , "" , comment, A = ALIGN ) ?;
415
+ if tcx. sess . opts . unstable_opts . mir_include_spans {
416
+ let mut extra_comments = ExtraComments { tcx, comments : vec ! [ ] } ;
417
+ visit_op ( & mut extra_comments) ;
418
+ for comment in extra_comments. comments {
419
+ writeln ! ( write, "{:A$} // {}" , "" , comment, A = ALIGN ) ?;
420
+ }
407
421
}
408
422
Ok ( ( ) )
409
423
}
@@ -522,13 +536,8 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
522
536
}
523
537
}
524
538
525
- fn comment ( tcx : TyCtxt < ' _ > , SourceInfo { span, scope } : SourceInfo , function_span : Span ) -> String {
526
- let location = if tcx. sess . opts . unstable_opts . mir_pretty_relative_line_numbers {
527
- tcx. sess . source_map ( ) . span_to_relative_line_string ( span, function_span)
528
- } else {
529
- tcx. sess . source_map ( ) . span_to_embeddable_string ( span)
530
- } ;
531
-
539
+ fn comment ( tcx : TyCtxt < ' _ > , SourceInfo { span, scope } : SourceInfo ) -> String {
540
+ let location = tcx. sess . source_map ( ) . span_to_embeddable_string ( span) ;
532
541
format ! ( "scope {} at {}" , scope. index( ) , location, )
533
542
}
534
543
@@ -560,13 +569,17 @@ fn write_scope_tree(
560
569
var_debug_info. value,
561
570
) ;
562
571
563
- writeln ! (
564
- w,
565
- "{0:1$} // in {2}" ,
566
- indented_debug_info,
567
- ALIGN ,
568
- comment( tcx, var_debug_info. source_info, body. span) ,
569
- ) ?;
572
+ if tcx. sess . opts . unstable_opts . mir_include_spans {
573
+ writeln ! (
574
+ w,
575
+ "{0:1$} // in {2}" ,
576
+ indented_debug_info,
577
+ ALIGN ,
578
+ comment( tcx, var_debug_info. source_info) ,
579
+ ) ?;
580
+ } else {
581
+ writeln ! ( w, "{}" , indented_debug_info) ?;
582
+ }
570
583
}
571
584
572
585
// Local variable types.
@@ -594,14 +607,18 @@ fn write_scope_tree(
594
607
595
608
let local_name = if local == RETURN_PLACE { " return place" } else { "" } ;
596
609
597
- writeln ! (
598
- w,
599
- "{0:1$} //{2} in {3}" ,
600
- indented_decl,
601
- ALIGN ,
602
- local_name,
603
- comment( tcx, local_decl. source_info, body. span) ,
604
- ) ?;
610
+ if tcx. sess . opts . unstable_opts . mir_include_spans {
611
+ writeln ! (
612
+ w,
613
+ "{0:1$} //{2} in {3}" ,
614
+ indented_decl,
615
+ ALIGN ,
616
+ local_name,
617
+ comment( tcx, local_decl. source_info) ,
618
+ ) ?;
619
+ } else {
620
+ writeln ! ( w, "{}" , indented_decl, ) ?;
621
+ }
605
622
}
606
623
607
624
let Some ( children) = scope_tree. get ( & parent) else {
@@ -627,14 +644,18 @@ fn write_scope_tree(
627
644
628
645
let indented_header = format ! ( "{0:1$}scope {2}{3} {{" , "" , indent, child. index( ) , special) ;
629
646
630
- if let Some ( span) = span {
631
- writeln ! (
632
- w,
633
- "{0:1$} // at {2}" ,
634
- indented_header,
635
- ALIGN ,
636
- tcx. sess. source_map( ) . span_to_embeddable_string( span) ,
637
- ) ?;
647
+ if tcx. sess . opts . unstable_opts . mir_include_spans {
648
+ if let Some ( span) = span {
649
+ writeln ! (
650
+ w,
651
+ "{0:1$} // at {2}" ,
652
+ indented_header,
653
+ ALIGN ,
654
+ tcx. sess. source_map( ) . span_to_embeddable_string( span) ,
655
+ ) ?;
656
+ } else {
657
+ writeln ! ( w, "{}" , indented_header) ?;
658
+ }
638
659
} else {
639
660
writeln ! ( w, "{}" , indented_header) ?;
640
661
}
0 commit comments