@@ -636,7 +636,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
636
636
item. id ) ;
637
637
638
638
for field in struct_def. fields . iter ( ) {
639
- self . process_struct_field_def ( field, enum_name [ ] , variant. node . id ) ;
639
+ self . process_struct_field_def ( field, qualname [ ] , variant. node . id ) ;
640
640
self . visit_ty ( & * field. node . ty ) ;
641
641
}
642
642
}
@@ -763,37 +763,38 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
763
763
}
764
764
765
765
fn process_path ( & mut self ,
766
- ex : & ast:: Expr ,
767
- path : & ast:: Path ) {
766
+ id : NodeId ,
767
+ span : Span ,
768
+ path : & ast:: Path ,
769
+ ref_kind : Option < recorder:: Row > ) {
768
770
if generated_code ( path. span ) {
769
771
return
770
772
}
771
773
772
774
let def_map = self . analysis . ty_cx . def_map . borrow ( ) ;
773
- if !def_map. contains_key ( & ex. id ) {
774
- self . sess . span_bug ( ex. span ,
775
- format ! ( "def_map has no key for {} in visit_expr" ,
776
- ex. id) [ ] ) ;
775
+ if !def_map. contains_key ( & id) {
776
+ self . sess . span_bug ( span,
777
+ format ! ( "def_map has no key for {} in visit_expr" , id) [ ] ) ;
777
778
}
778
- let def = & ( * def_map) [ ex . id ] ;
779
- let sub_span = self . span . span_for_last_ident ( ex . span ) ;
779
+ let def = & ( * def_map) [ id] ;
780
+ let sub_span = self . span . span_for_last_ident ( span) ;
780
781
match * def {
781
782
def:: DefUpvar ( ..) |
782
783
def:: DefLocal ( ..) |
783
784
def:: DefStatic ( ..) |
784
785
def:: DefConst ( ..) |
785
- def:: DefVariant ( ..) => self . fmt . ref_str ( recorder:: VarRef ,
786
- ex . span ,
786
+ def:: DefVariant ( ..) => self . fmt . ref_str ( ref_kind . unwrap_or ( recorder:: VarRef ) ,
787
+ span,
787
788
sub_span,
788
789
def. def_id ( ) ,
789
790
self . cur_scope ) ,
790
791
def:: DefStruct ( def_id) => self . fmt . ref_str ( recorder:: StructRef ,
791
- ex . span ,
792
+ span,
792
793
sub_span,
793
794
def_id,
794
- self . cur_scope ) ,
795
+ self . cur_scope ) ,
795
796
def:: DefStaticMethod ( declid, provenence) => {
796
- let sub_span = self . span . sub_span_for_meth_name ( ex . span ) ;
797
+ let sub_span = self . span . sub_span_for_meth_name ( span) ;
797
798
let defid = if declid. krate == ast:: LOCAL_CRATE {
798
799
let ti = ty:: impl_or_trait_item ( & self . analysis . ty_cx ,
799
800
declid) ;
@@ -828,34 +829,31 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
828
829
} else {
829
830
None
830
831
} ;
831
- self . fmt . meth_call_str ( ex . span ,
832
+ self . fmt . meth_call_str ( span,
832
833
sub_span,
833
834
defid,
834
835
Some ( declid) ,
835
836
self . cur_scope ) ;
836
837
} ,
837
- def:: DefFn ( def_id, _) => self . fmt . fn_call_str ( ex . span ,
838
- sub_span,
839
- def_id,
840
- self . cur_scope ) ,
841
- _ => self . sess . span_bug ( ex . span ,
838
+ def:: DefFn ( def_id, _) => self . fmt . fn_call_str ( span,
839
+ sub_span,
840
+ def_id,
841
+ self . cur_scope ) ,
842
+ _ => self . sess . span_bug ( span,
842
843
format ! ( "Unexpected def kind while looking up path in '{}'" ,
843
- self . span. snippet( ex . span) ) [ ] ) ,
844
+ self . span. snippet( span) ) [ ] ) ,
844
845
}
845
846
// modules or types in the path prefix
846
847
match * def {
847
- def:: DefStaticMethod ( ..) => {
848
- self . write_sub_path_trait_truncated ( path) ;
849
- } ,
848
+ def:: DefStaticMethod ( ..) => self . write_sub_path_trait_truncated ( path) ,
850
849
def:: DefLocal ( _) |
851
850
def:: DefStatic ( _, _) |
852
851
def:: DefConst ( ..) |
853
852
def:: DefStruct ( _) |
853
+ def:: DefVariant ( ..) |
854
854
def:: DefFn ( ..) => self . write_sub_paths_truncated ( path) ,
855
855
_ => { } ,
856
856
}
857
-
858
- visit:: walk_path ( self , path) ;
859
857
}
860
858
861
859
fn process_struct_lit ( & mut self ,
@@ -982,18 +980,19 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
982
980
}
983
981
} ;
984
982
for & Spanned { node : ref field, span } in fields. iter ( ) {
985
- self . visit_pat ( & * field . pat ) ;
983
+ let sub_span = self . span . span_for_first_ident ( span ) ;
986
984
let fields = ty:: lookup_struct_fields ( & self . analysis . ty_cx , struct_def) ;
987
985
for f in fields. iter ( ) {
988
986
if f. name == field. ident . name {
989
987
self . fmt . ref_str ( recorder:: VarRef ,
990
- p . span ,
991
- Some ( span ) ,
988
+ span,
989
+ sub_span ,
992
990
f. id ,
993
991
self . cur_scope ) ;
994
992
break ;
995
993
}
996
994
}
995
+ self . visit_pat ( & * field. pat ) ;
997
996
}
998
997
}
999
998
ast:: PatEnum ( ref path, _) => {
@@ -1162,8 +1161,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1162
1161
}
1163
1162
1164
1163
match i. node {
1165
- ast:: ViewItemUse ( ref path ) => {
1166
- match path . node {
1164
+ ast:: ViewItemUse ( ref item ) => {
1165
+ match item . node {
1167
1166
ast:: ViewPathSimple ( ident, ref path, id) => {
1168
1167
let sub_span = self . span . span_for_last_ident ( path. span ) ;
1169
1168
let mod_id = match self . lookup_type_ref ( id) {
@@ -1184,7 +1183,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1184
1183
// 'use' always introduces an alias, if there is not an explicit
1185
1184
// one, there is an implicit one.
1186
1185
let sub_span =
1187
- match self . span . sub_span_before_token ( path . span , token :: Eq ) {
1186
+ match self . span . sub_span_after_keyword ( item . span , keywords :: As ) {
1188
1187
Some ( sub_span) => Some ( sub_span) ,
1189
1188
None => sub_span,
1190
1189
} ;
@@ -1308,7 +1307,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1308
1307
// because just walking the callee path does what we want.
1309
1308
visit:: walk_expr ( self , ex) ;
1310
1309
} ,
1311
- ast:: ExprPath ( ref path) => self . process_path ( ex, path) ,
1310
+ ast:: ExprPath ( ref path) => {
1311
+ self . process_path ( ex. id , ex. span , path, None ) ;
1312
+ visit:: walk_path ( self , path) ;
1313
+ }
1312
1314
ast:: ExprStruct ( ref path, ref fields, ref base) =>
1313
1315
self . process_struct_lit ( ex, path, fields, base) ,
1314
1316
ast:: ExprMethodCall ( _, _, ref args) => self . process_method_call ( ex, args) ,
@@ -1405,46 +1407,50 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1405
1407
fn visit_arm ( & mut self , arm : & ast:: Arm ) {
1406
1408
assert ! ( self . collected_paths. len( ) == 0 && !self . collecting) ;
1407
1409
self . collecting = true ;
1408
-
1409
1410
for pattern in arm. pats . iter ( ) {
1410
1411
// collect paths from the arm's patterns
1411
1412
self . visit_pat ( & * * pattern) ;
1412
1413
}
1413
- self . collecting = false ;
1414
+
1415
+ // This is to get around borrow checking, because we need mut self to call process_path.
1416
+ let mut paths_to_process = vec ! [ ] ;
1414
1417
// process collected paths
1415
1418
for & ( id, ref p, ref immut, ref_kind) in self . collected_paths . iter ( ) {
1416
- let value = if * immut {
1417
- self . span . snippet ( p. span ) . to_string ( )
1418
- } else {
1419
- "<mutable>" . to_string ( )
1420
- } ;
1421
- let sub_span = self . span . span_for_first_ident ( p. span ) ;
1422
1419
let def_map = self . analysis . ty_cx . def_map . borrow ( ) ;
1423
1420
if !def_map. contains_key ( & id) {
1424
1421
self . sess . span_bug ( p. span ,
1425
- format ! ( "def_map has no key for {} in visit_arm" ,
1426
- id) [ ] ) ;
1422
+ format ! ( "def_map has no key for {} in visit_arm" , id) [ ] ) ;
1427
1423
}
1428
1424
let def = & ( * def_map) [ id] ;
1429
1425
match * def {
1430
- def:: DefLocal ( id) => self . fmt . variable_str ( p. span ,
1431
- sub_span,
1432
- id,
1433
- path_to_string ( p) [ ] ,
1434
- value[ ] ,
1435
- "" ) ,
1436
- def:: DefVariant ( _, id, _) => self . fmt . ref_str ( ref_kind,
1437
- p. span ,
1438
- sub_span,
1439
- id,
1440
- self . cur_scope ) ,
1441
- // FIXME(nrc) what is this doing here?
1426
+ def:: DefLocal ( id) => {
1427
+ let value = if * immut {
1428
+ self . span . snippet ( p. span ) . to_string ( )
1429
+ } else {
1430
+ "<mutable>" . to_string ( )
1431
+ } ;
1432
+
1433
+ assert ! ( p. segments. len( ) == 1 , "qualified path for local variable def in arm" ) ;
1434
+ self . fmt . variable_str ( p. span ,
1435
+ Some ( p. span ) ,
1436
+ id,
1437
+ path_to_string ( p) [ ] ,
1438
+ value[ ] ,
1439
+ "" )
1440
+ }
1441
+ def:: DefVariant ( ..) => {
1442
+ paths_to_process. push ( ( id, p. span , p. clone ( ) , Some ( ref_kind) ) )
1443
+ }
1444
+ // FIXME(nrc) what are these doing here?
1442
1445
def:: DefStatic ( _, _) => { }
1443
1446
def:: DefConst ( ..) => { }
1444
- _ => error ! ( "unexpected definition kind when processing collected paths: {}" ,
1445
- * def)
1447
+ _ => error ! ( "unexpected definition kind when processing collected paths: {}" , * def)
1446
1448
}
1447
1449
}
1450
+ for & ( id, span, ref path, ref_kind) in paths_to_process. iter ( ) {
1451
+ self . process_path ( id, span, path, ref_kind) ;
1452
+ }
1453
+ self . collecting = false ;
1448
1454
self . collected_paths . clear ( ) ;
1449
1455
visit:: walk_expr_opt ( self , & arm. guard ) ;
1450
1456
self . visit_expr ( & * arm. body ) ;
0 commit comments