@@ -897,32 +897,23 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
897
897
}
898
898
}
899
899
900
- fn process_var_decl_multi ( & mut self , pats : & ' l [ P < ast:: Pat > ] ) {
900
+ fn process_var_decl ( & mut self , pat : & ' l ast:: Pat ) {
901
+ // The pattern could declare multiple new vars,
902
+ // we must walk the pattern and collect them all.
901
903
let mut collector = PathCollector :: new ( ) ;
902
- for pattern in pats {
903
- // collect paths from the arm's patterns
904
- collector. visit_pat ( & pattern) ;
905
- self . visit_pat ( & pattern) ;
906
- }
904
+ collector. visit_pat ( & pat) ;
905
+ self . visit_pat ( & pat) ;
907
906
908
- // process collected paths
909
- for ( id, ident, immut ) in collector. collected_idents {
907
+ // Process collected paths.
908
+ for ( id, ident, _ ) in collector. collected_idents {
910
909
match self . save_ctxt . get_path_res ( id) {
911
910
Res :: Local ( hir_id) => {
912
- let mut value = if immut == ast:: Mutability :: Immutable {
913
- self . span . snippet ( ident. span )
914
- } else {
915
- "<mutable>" . to_owned ( )
916
- } ;
917
911
let id = self . tcx . hir ( ) . hir_to_node_id ( hir_id) ;
918
- let typ = self . save_ctxt
919
- . tables
920
- . node_type_opt ( hir_id)
912
+ let typ = self . save_ctxt . tables . node_type_opt ( hir_id)
921
913
. map ( |t| t. to_string ( ) )
922
914
. unwrap_or_default ( ) ;
923
- value. push_str ( ": " ) ;
924
- value. push_str ( & typ) ;
925
915
916
+ // Rust uses the id of the pattern for var lookups, so we'll use it too.
926
917
if !self . span . filter_generated ( ident. span ) {
927
918
let qualname = format ! ( "{}${}" , ident. to_string( ) , id) ;
928
919
let id = id_from_node_id ( id, & self . save_ctxt ) ;
@@ -972,61 +963,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
972
963
}
973
964
}
974
965
975
- fn process_var_decl ( & mut self , p : & ' l ast:: Pat , value : String ) {
976
- // The local could declare multiple new vars, we must walk the
977
- // pattern and collect them all.
978
- let mut collector = PathCollector :: new ( ) ;
979
- collector. visit_pat ( & p) ;
980
- self . visit_pat ( & p) ;
981
-
982
- for ( id, ident, immut) in collector. collected_idents {
983
- let mut value = match immut {
984
- ast:: Mutability :: Immutable => value. to_string ( ) ,
985
- _ => String :: new ( ) ,
986
- } ;
987
- let hir_id = self . tcx . hir ( ) . node_to_hir_id ( id) ;
988
- let typ = match self . save_ctxt . tables . node_type_opt ( hir_id) {
989
- Some ( typ) => {
990
- let typ = typ. to_string ( ) ;
991
- if !value. is_empty ( ) {
992
- value. push_str ( ": " ) ;
993
- }
994
- value. push_str ( & typ) ;
995
- typ
996
- }
997
- None => String :: new ( ) ,
998
- } ;
999
-
1000
- // Rust uses the id of the pattern for var lookups, so we'll use it too.
1001
- if !self . span . filter_generated ( ident. span ) {
1002
- let qualname = format ! ( "{}${}" , ident. to_string( ) , id) ;
1003
- let id = id_from_node_id ( id, & self . save_ctxt ) ;
1004
- let span = self . span_from_span ( ident. span ) ;
1005
-
1006
- self . dumper . dump_def (
1007
- & Access {
1008
- public : false ,
1009
- reachable : false ,
1010
- } ,
1011
- Def {
1012
- kind : DefKind :: Local ,
1013
- id,
1014
- span,
1015
- name : ident. to_string ( ) ,
1016
- qualname,
1017
- value : typ,
1018
- parent : None ,
1019
- children : vec ! [ ] ,
1020
- decl_id : None ,
1021
- docs : String :: new ( ) ,
1022
- sig : None ,
1023
- attributes : vec ! [ ] ,
1024
- } ,
1025
- ) ;
1026
- }
1027
- }
1028
- }
1029
-
1030
966
/// Extracts macro use and definition information from the AST node defined
1031
967
/// by the given NodeId, using the expansion information from the node's
1032
968
/// span.
@@ -1565,14 +1501,13 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1565
1501
} ) ;
1566
1502
}
1567
1503
ast:: ExprKind :: ForLoop ( ref pattern, ref subexpression, ref block, _) => {
1568
- let value = self . span . snippet ( subexpression. span ) ;
1569
- self . process_var_decl ( pattern, value) ;
1504
+ self . process_var_decl ( pattern) ;
1570
1505
debug ! ( "for loop, walk sub-expr: {:?}" , subexpression. node) ;
1571
1506
self . visit_expr ( subexpression) ;
1572
1507
visit:: walk_block ( self , block) ;
1573
1508
}
1574
- ast:: ExprKind :: Let ( ref pats , ref scrutinee) => {
1575
- self . process_var_decl_multi ( pats ) ;
1509
+ ast:: ExprKind :: Let ( ref pat , ref scrutinee) => {
1510
+ self . process_var_decl ( pat ) ;
1576
1511
self . visit_expr ( scrutinee) ;
1577
1512
}
1578
1513
ast:: ExprKind :: Repeat ( ref element, ref count) => {
@@ -1599,7 +1534,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1599
1534
}
1600
1535
1601
1536
fn visit_arm ( & mut self , arm : & ' l ast:: Arm ) {
1602
- self . process_var_decl_multi ( & arm. pats ) ;
1537
+ self . process_var_decl ( & arm. pat ) ;
1603
1538
if let Some ( expr) = & arm. guard {
1604
1539
self . visit_expr ( expr) ;
1605
1540
}
@@ -1617,11 +1552,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1617
1552
1618
1553
fn visit_local ( & mut self , l : & ' l ast:: Local ) {
1619
1554
self . process_macro_use ( l. span ) ;
1620
- let value = l. init
1621
- . as_ref ( )
1622
- . map ( |i| self . span . snippet ( i. span ) )
1623
- . unwrap_or_default ( ) ;
1624
- self . process_var_decl ( & l. pat , value) ;
1555
+ self . process_var_decl ( & l. pat ) ;
1625
1556
1626
1557
// Just walk the initialiser and type (don't want to walk the pattern again).
1627
1558
walk_list ! ( self , visit_ty, & l. ty) ;
0 commit comments