@@ -353,14 +353,22 @@ where
353353 for  statement in  & data. statements  { 
354354 extra_data ( PassWhere :: BeforeLocation ( current_location) ,  w) ?; 
355355 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+  } 
364372
365373 write_extra ( tcx,  w,  |visitor| { 
366374 visitor. visit_statement ( statement,  current_location) ; 
@@ -374,14 +382,18 @@ where
374382 // Terminator at the bottom. 
375383 extra_data ( PassWhere :: BeforeLocation ( current_location) ,  w) ?; 
376384 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+  } 
385397
386398 write_extra ( tcx,  w,  |visitor| { 
387399 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:
400412where 
401413 F :  FnMut ( & mut  ExtraComments < ' tcx > ) , 
402414{ 
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+  } 
407421 } 
408422 Ok ( ( ) ) 
409423} 
@@ -522,13 +536,8 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
522536 } 
523537} 
524538
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) ; 
532541 format ! ( "scope {} at {}" ,  scope. index( ) ,  location, ) 
533542} 
534543
@@ -560,13 +569,17 @@ fn write_scope_tree(
560569 var_debug_info. value, 
561570 ) ; 
562571
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+  } 
570583 } 
571584
572585 // Local variable types. 
@@ -594,14 +607,18 @@ fn write_scope_tree(
594607
595608 let  local_name = if  local == RETURN_PLACE  {  " return place"  }  else  {  ""  } ; 
596609
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+  } 
605622 } 
606623
607624 let  Some ( children)  = scope_tree. get ( & parent)  else  { 
@@ -627,14 +644,18 @@ fn write_scope_tree(
627644
628645 let  indented_header = format ! ( "{0:1$}scope {2}{3} {{" ,  "" ,  indent,  child. index( ) ,  special) ; 
629646
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+  } 
638659 }  else  { 
639660 writeln ! ( w,  "{}" ,  indented_header) ?; 
640661 } 
0 commit comments