@@ -461,9 +461,7 @@ fn comment(tcx: TyCtxt<'_, '_, '_>, SourceInfo { span, scope }: SourceInfo) -> S
461
461
)
462
462
}
463
463
464
- /// Prints user-defined variables in a scope tree.
465
- ///
466
- /// Returns the total number of variables printed.
464
+ /// Prints local variables in a scope tree.
467
465
fn write_scope_tree (
468
466
tcx : TyCtxt < ' _ , ' _ , ' _ > ,
469
467
mir : & Mir < ' _ > ,
@@ -474,57 +472,64 @@ fn write_scope_tree(
474
472
) -> io:: Result < ( ) > {
475
473
let indent = depth * INDENT . len ( ) ;
476
474
475
+ // Local variable types (including the user's name in a comment).
476
+ for ( local, local_decl) in mir. local_decls . iter_enumerated ( ) {
477
+ if ( 1 ..mir. arg_count +1 ) . contains ( & local. index ( ) ) {
478
+ // Skip over argument locals, they're printed in the signature.
479
+ continue ;
480
+ }
481
+
482
+ if local_decl. source_info . scope != parent {
483
+ // Not declared in this scope.
484
+ continue ;
485
+ }
486
+
487
+ let mut_str = if local_decl. mutability == Mutability :: Mut {
488
+ "mut "
489
+ } else {
490
+ ""
491
+ } ;
492
+
493
+ let mut indented_decl = format ! (
494
+ "{0:1$}let {2}{3:?}: {4:?}" ,
495
+ INDENT ,
496
+ indent,
497
+ mut_str,
498
+ local,
499
+ local_decl. ty
500
+ ) ;
501
+ for user_ty in local_decl. user_ty . projections ( ) {
502
+ write ! ( indented_decl, " as {:?}" , user_ty) . unwrap ( ) ;
503
+ }
504
+ indented_decl. push_str ( ";" ) ;
505
+
506
+ let local_name = if local == RETURN_PLACE {
507
+ format ! ( " return place" )
508
+ } else if let Some ( name) = local_decl. name {
509
+ format ! ( " \" {}\" " , name)
510
+ } else {
511
+ String :: new ( )
512
+ } ;
513
+
514
+ writeln ! (
515
+ w,
516
+ "{0:1$} //{2} in {3}" ,
517
+ indented_decl,
518
+ ALIGN ,
519
+ local_name,
520
+ comment( tcx, local_decl. source_info) ,
521
+ ) ?;
522
+ }
523
+
477
524
let children = match scope_tree. get ( & parent) {
478
- Some ( children ) => children ,
525
+ Some ( childs ) => childs ,
479
526
None => return Ok ( ( ) ) ,
480
527
} ;
481
528
482
529
for & child in children {
483
- let data = & mir. source_scopes [ child] ;
484
- assert_eq ! ( data. parent_scope, Some ( parent) ) ;
530
+ assert_eq ! ( mir. source_scopes[ child] . parent_scope, Some ( parent) ) ;
485
531
writeln ! ( w, "{0:1$}scope {2} {{" , "" , indent, child. index( ) ) ?;
486
-
487
- // User variable types (including the user's name in a comment).
488
- for local in mir. vars_iter ( ) {
489
- let var = & mir. local_decls [ local] ;
490
- let ( name, source_info) = if var. source_info . scope == child {
491
- ( var. name . unwrap ( ) , var. source_info )
492
- } else {
493
- // Not a variable or not declared in this scope.
494
- continue ;
495
- } ;
496
-
497
- let mut_str = if var. mutability == Mutability :: Mut {
498
- "mut "
499
- } else {
500
- ""
501
- } ;
502
-
503
- let indent = indent + INDENT . len ( ) ;
504
- let mut indented_var = format ! (
505
- "{0:1$}let {2}{3:?}: {4:?}" ,
506
- INDENT ,
507
- indent,
508
- mut_str,
509
- local,
510
- var. ty
511
- ) ;
512
- for user_ty in var. user_ty . projections ( ) {
513
- write ! ( indented_var, " as {:?}" , user_ty) . unwrap ( ) ;
514
- }
515
- indented_var. push_str ( ";" ) ;
516
- writeln ! (
517
- w,
518
- "{0:1$} // \" {2}\" in {3}" ,
519
- indented_var,
520
- ALIGN ,
521
- name,
522
- comment( tcx, source_info)
523
- ) ?;
524
- }
525
-
526
532
write_scope_tree ( tcx, mir, scope_tree, w, child, depth + 1 ) ?;
527
-
528
533
writeln ! ( w, "{0:1$}}}" , "" , depth * INDENT . len( ) ) ?;
529
534
}
530
535
@@ -556,19 +561,8 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>(
556
561
}
557
562
}
558
563
559
- // Print return place
560
- let indented_retptr = format ! ( "{}let mut {:?}: {};" ,
561
- INDENT ,
562
- RETURN_PLACE ,
563
- mir. local_decls[ RETURN_PLACE ] . ty) ;
564
- writeln ! ( w, "{0:1$} // return place" ,
565
- indented_retptr,
566
- ALIGN ) ?;
567
-
568
564
write_scope_tree ( tcx, mir, & scope_tree, w, OUTERMOST_SOURCE_SCOPE , 1 ) ?;
569
565
570
- write_temp_decls ( mir, w) ?;
571
-
572
566
// Add an empty line before the first block is printed.
573
567
writeln ! ( w, "" ) ?;
574
568
@@ -632,22 +626,6 @@ fn write_mir_sig(
632
626
Ok ( ( ) )
633
627
}
634
628
635
- fn write_temp_decls ( mir : & Mir < ' _ > , w : & mut dyn Write ) -> io:: Result < ( ) > {
636
- // Compiler-introduced temporary types.
637
- for temp in mir. temps_iter ( ) {
638
- writeln ! (
639
- w,
640
- "{}let {}{:?}: {};" ,
641
- INDENT ,
642
- if mir. local_decls[ temp] . mutability == Mutability :: Mut { "mut " } else { "" } ,
643
- temp,
644
- mir. local_decls[ temp] . ty
645
- ) ?;
646
- }
647
-
648
- Ok ( ( ) )
649
- }
650
-
651
629
fn write_user_type_annotations ( mir : & Mir < ' _ > , w : & mut dyn Write ) -> io:: Result < ( ) > {
652
630
if !mir. user_type_annotations . is_empty ( ) {
653
631
writeln ! ( w, "| User Type Annotations" ) ?;
0 commit comments