@@ -814,7 +814,13 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
814
814
sub_span,
815
815
def_id,
816
816
self . cur_scope ) ,
817
- def:: DefStaticMethod ( declid, provenence) => {
817
+ def:: DefTy ( def_id, _) => self . fmt . ref_str ( recorder:: TypeRef ,
818
+ span,
819
+ sub_span,
820
+ def_id,
821
+ self . cur_scope ) ,
822
+ def:: DefStaticMethod ( declid, provenence) |
823
+ def:: DefMethod ( declid, _, provenence) => {
818
824
let sub_span = self . span . sub_span_for_meth_name ( span) ;
819
825
let defid = if declid. krate == ast:: LOCAL_CRATE {
820
826
let ti = ty:: impl_or_trait_item ( & self . analysis . ty_cx ,
@@ -856,13 +862,17 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
856
862
Some ( declid) ,
857
863
self . cur_scope ) ;
858
864
} ,
859
- def:: DefFn ( def_id, _) => self . fmt . fn_call_str ( span,
860
- sub_span,
861
- def_id,
862
- self . cur_scope ) ,
865
+ def:: DefFn ( def_id, _) => {
866
+ self . fmt . fn_call_str ( span,
867
+ sub_span,
868
+ def_id,
869
+ self . cur_scope )
870
+ }
863
871
_ => self . sess . span_bug ( span,
864
- & format ! ( "Unexpected def kind while looking up path in '{}'" ,
865
- self . span. snippet( span) ) [ ] ) ,
872
+ & format ! ( "Unexpected def kind while looking \
873
+ up path in `{}`: `{:?}`",
874
+ self . span. snippet( span) ,
875
+ * def) [ ] ) ,
866
876
}
867
877
// modules or types in the path prefix
868
878
match * def {
@@ -886,21 +896,21 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
886
896
return
887
897
}
888
898
889
- let mut struct_def: Option < DefId > = None ;
890
- match self . lookup_type_ref ( ex. id ) {
891
- Some ( id) => {
892
- struct_def = Some ( id) ;
899
+ self . write_sub_paths_truncated ( path, false ) ;
900
+
901
+ let ty = & ty:: expr_ty_adjusted ( & self . analysis . ty_cx , ex) . sty ;
902
+ let struct_def = match * ty {
903
+ ty:: ty_struct( def_id, _) => {
893
904
let sub_span = self . span . span_for_last_ident ( path. span ) ;
894
905
self . fmt . ref_str ( recorder:: StructRef ,
895
906
path. span ,
896
907
sub_span,
897
- id ,
908
+ def_id ,
898
909
self . cur_scope ) ;
899
- } ,
900
- None => ( )
901
- }
902
-
903
- self . write_sub_paths_truncated ( path, false ) ;
910
+ Some ( def_id)
911
+ }
912
+ _ => None
913
+ } ;
904
914
905
915
for field in fields. iter ( ) {
906
916
match struct_def {
@@ -1335,8 +1345,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1335
1345
}
1336
1346
1337
1347
self . visit_expr ( & * * sub_ex) ;
1338
-
1339
- match ty :: expr_ty_adjusted ( & self . analysis . ty_cx , & * * sub_ex ) . sty {
1348
+ let ty = & ty :: expr_ty_adjusted ( & self . analysis . ty_cx , & * * sub_ex ) . sty ;
1349
+ match * ty {
1340
1350
ty:: ty_struct( def_id, _) => {
1341
1351
let fields = ty:: lookup_struct_fields ( & self . analysis . ty_cx , def_id) ;
1342
1352
for f in fields. iter ( ) {
@@ -1350,9 +1360,9 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1350
1360
break ;
1351
1361
}
1352
1362
}
1353
- } ,
1363
+ }
1354
1364
_ => self . sess . span_bug ( ex. span ,
1355
- "Expected struct type, but not ty_struct" ) ,
1365
+ & format ! ( "Expected struct type, found {:?}" , ty ) [ ] ) ,
1356
1366
}
1357
1367
} ,
1358
1368
ast:: ExprTupField ( ref sub_ex, idx) => {
@@ -1362,12 +1372,13 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1362
1372
1363
1373
self . visit_expr ( & * * sub_ex) ;
1364
1374
1365
- match ty:: expr_ty_adjusted ( & self . analysis . ty_cx , & * * sub_ex) . sty {
1375
+ let ty = & ty:: expr_ty_adjusted ( & self . analysis . ty_cx , & * * sub_ex) . sty ;
1376
+ match * ty {
1366
1377
ty:: ty_struct( def_id, _) => {
1367
1378
let fields = ty:: lookup_struct_fields ( & self . analysis . ty_cx , def_id) ;
1368
1379
for ( i, f) in fields. iter ( ) . enumerate ( ) {
1369
1380
if i == idx. node {
1370
- let sub_span = self . span . span_for_last_ident ( ex. span ) ;
1381
+ let sub_span = self . span . sub_span_after_token ( ex. span , token :: Dot ) ;
1371
1382
self . fmt . ref_str ( recorder:: VarRef ,
1372
1383
ex. span ,
1373
1384
sub_span,
@@ -1376,9 +1387,11 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1376
1387
break ;
1377
1388
}
1378
1389
}
1379
- } ,
1390
+ }
1391
+ ty:: ty_tup( _) => { }
1380
1392
_ => self . sess . span_bug ( ex. span ,
1381
- "Expected struct type, but not ty_struct" ) ,
1393
+ & format ! ( "Expected struct or tuple \
1394
+ type, found {:?}", ty) [ ] ) ,
1382
1395
}
1383
1396
} ,
1384
1397
ast:: ExprClosure ( _, _, ref decl, ref body) => {
@@ -1454,7 +1467,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1454
1467
& value[ ] ,
1455
1468
"" )
1456
1469
}
1457
- def:: DefVariant ( ..) => {
1470
+ def:: DefVariant ( ..) | def :: DefTy ( .. ) | def :: DefStruct ( .. ) => {
1458
1471
paths_to_process. push ( ( id, p. clone ( ) , Some ( ref_kind) ) )
1459
1472
}
1460
1473
// FIXME(nrc) what are these doing here?
0 commit comments