@@ -48,12 +48,13 @@ use syntax::ptr::P;
48
48
use syntax:: codemap:: Spanned ;
49
49
use syntax_pos:: * ;
50
50
51
- use super :: { escape, generated_code, SaveContext , PathCollector , docs_for_attrs} ;
52
- use super :: data:: * ;
53
- use super :: dump:: Dump ;
54
- use super :: external_data:: { Lower , make_def_id} ;
55
- use super :: span_utils:: SpanUtils ;
56
- use super :: recorder;
51
+ use { escape, generated_code, SaveContext , PathCollector , docs_for_attrs} ;
52
+ use data:: * ;
53
+ use dump:: Dump ;
54
+ use external_data:: { Lower , make_def_id} ;
55
+ use recorder;
56
+ use span_utils:: SpanUtils ;
57
+ use sig;
57
58
58
59
use rls_data:: ExternalCrateData ;
59
60
@@ -391,13 +392,13 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
391
392
sig : & ' l ast:: MethodSig ,
392
393
body : Option < & ' l ast:: Block > ,
393
394
id : ast:: NodeId ,
394
- name : ast:: Name ,
395
+ name : ast:: Ident ,
395
396
vis : Visibility ,
396
397
attrs : & ' l [ Attribute ] ,
397
398
span : Span ) {
398
399
debug ! ( "process_method: {}:{}" , id, name) ;
399
400
400
- if let Some ( method_data) = self . save_ctxt . get_method_data ( id, name, span) {
401
+ if let Some ( method_data) = self . save_ctxt . get_method_data ( id, name. name , span) {
401
402
402
403
let sig_str = :: make_signature ( & sig. decl , & sig. generics ) ;
403
404
if body. is_some ( ) {
@@ -423,7 +424,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
423
424
Some ( id) => {
424
425
for item in self . tcx . associated_items ( id) {
425
426
if item. kind == ty:: AssociatedKind :: Method {
426
- if item. name == name {
427
+ if item. name == name. name {
427
428
decl_id = Some ( item. def_id ) ;
428
429
break ;
429
430
}
@@ -455,7 +456,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
455
456
parent : trait_id,
456
457
visibility : vis,
457
458
docs : docs_for_attrs ( attrs) ,
458
- sig : method_data . sig ,
459
+ sig : sig:: method_signature ( id , name , sig , & self . save_ctxt ) ,
459
460
attributes : attrs. to_vec ( ) ,
460
461
} . lower ( self . tcx ) ) ;
461
462
}
@@ -580,13 +581,14 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
580
581
name : ast:: Name ,
581
582
span : Span ,
582
583
typ : & ' l ast:: Ty ,
583
- expr : & ' l ast:: Expr ,
584
+ expr : Option < & ' l ast:: Expr > ,
584
585
parent_id : DefId ,
585
586
vis : Visibility ,
586
587
attrs : & ' l [ Attribute ] ) {
587
588
let qualname = format ! ( "::{}" , self . tcx. node_path_str( id) ) ;
588
589
589
590
let sub_span = self . span . sub_span_after_keyword ( span, keywords:: Const ) ;
591
+ let value = expr. map ( |e| self . span . snippet ( e. span ) ) . unwrap_or ( String :: new ( ) ) ;
590
592
591
593
if !self . span . filter_generated ( sub_span, span) {
592
594
self . dumper . variable ( VariableData {
@@ -595,20 +597,22 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
595
597
id : id,
596
598
name : name. to_string ( ) ,
597
599
qualname : qualname,
598
- value : self . span . snippet ( expr . span ) ,
600
+ value : value ,
599
601
type_value : ty_to_string ( & typ) ,
600
602
scope : self . cur_scope ,
601
603
parent : Some ( parent_id) ,
602
604
visibility : vis,
603
605
docs : docs_for_attrs ( attrs) ,
604
- sig : None ,
606
+ sig : sig :: assoc_const_signature ( id , name , typ , expr , & self . save_ctxt ) ,
605
607
attributes : attrs. to_vec ( ) ,
606
608
} . lower ( self . tcx ) ) ;
607
609
}
608
610
609
611
// walk type and init value
610
612
self . visit_ty ( typ) ;
611
- self . visit_expr ( expr) ;
613
+ if let Some ( expr) = expr {
614
+ self . visit_expr ( expr) ;
615
+ }
612
616
}
613
617
614
618
// FIXME tuple structs should generate tuple-specific data.
@@ -646,7 +650,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
646
650
fields : fields,
647
651
visibility : From :: from ( & item. vis ) ,
648
652
docs : docs_for_attrs ( & item. attrs ) ,
649
- sig : self . save_ctxt . sig_base ( item ) ,
653
+ sig : sig :: item_signature ( item , & self . save_ctxt ) ,
650
654
attributes : item. attrs . clone ( ) ,
651
655
} . lower ( self . tcx ) ) ;
652
656
}
@@ -679,18 +683,6 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
679
683
qualname. push_str ( "::" ) ;
680
684
qualname. push_str ( & name) ;
681
685
682
- let text = self . span . signature_string_for_span ( variant. span ) ;
683
- let ident_start = text. find ( & name) . unwrap ( ) ;
684
- let ident_end = ident_start + name. len ( ) ;
685
- let sig = Signature {
686
- span : variant. span ,
687
- text : text,
688
- ident_start : ident_start,
689
- ident_end : ident_end,
690
- defs : vec ! [ ] ,
691
- refs : vec ! [ ] ,
692
- } ;
693
-
694
686
match variant. node . data {
695
687
ast:: VariantData :: Struct ( ref fields, _) => {
696
688
let sub_span = self . span . span_for_first_ident ( variant. span ) ;
@@ -712,7 +704,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
712
704
scope : enum_data. scope ,
713
705
parent : Some ( make_def_id ( item. id , & self . tcx . hir ) ) ,
714
706
docs : docs_for_attrs ( & variant. node . attrs ) ,
715
- sig : sig,
707
+ sig : sig:: variant_signature ( variant , & self . save_ctxt ) ,
716
708
attributes : variant. node . attrs . clone ( ) ,
717
709
} . lower ( self . tcx ) ) ;
718
710
}
@@ -739,7 +731,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
739
731
scope : enum_data. scope ,
740
732
parent : Some ( make_def_id ( item. id , & self . tcx . hir ) ) ,
741
733
docs : docs_for_attrs ( & variant. node . attrs ) ,
742
- sig : sig,
734
+ sig : sig:: variant_signature ( variant , & self . save_ctxt ) ,
743
735
attributes : variant. node . attrs . clone ( ) ,
744
736
} . lower ( self . tcx ) ) ;
745
737
}
@@ -811,7 +803,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
811
803
items : methods. iter ( ) . map ( |i| i. id ) . collect ( ) ,
812
804
visibility : From :: from ( & item. vis ) ,
813
805
docs : docs_for_attrs ( & item. attrs ) ,
814
- sig : self . save_ctxt . sig_base ( item ) ,
806
+ sig : sig :: item_signature ( item , & self . save_ctxt ) ,
815
807
attributes : item. attrs . clone ( ) ,
816
808
} . lower ( self . tcx ) ) ;
817
809
}
@@ -1133,12 +1125,12 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
1133
1125
fn process_trait_item ( & mut self , trait_item : & ' l ast:: TraitItem , trait_id : DefId ) {
1134
1126
self . process_macro_use ( trait_item. span , trait_item. id ) ;
1135
1127
match trait_item. node {
1136
- ast:: TraitItemKind :: Const ( ref ty, Some ( ref expr) ) => {
1128
+ ast:: TraitItemKind :: Const ( ref ty, ref expr) => {
1137
1129
self . process_assoc_const ( trait_item. id ,
1138
1130
trait_item. ident . name ,
1139
1131
trait_item. span ,
1140
1132
& ty,
1141
- & expr,
1133
+ expr. as_ref ( ) . map ( |e| & * * e ) ,
1142
1134
trait_id,
1143
1135
Visibility :: Public ,
1144
1136
& trait_item. attrs ) ;
@@ -1147,12 +1139,12 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
1147
1139
self . process_method ( sig,
1148
1140
body. as_ref ( ) . map ( |x| & * * x) ,
1149
1141
trait_item. id ,
1150
- trait_item. ident . name ,
1142
+ trait_item. ident ,
1151
1143
Visibility :: Public ,
1152
1144
& trait_item. attrs ,
1153
1145
trait_item. span ) ;
1154
1146
}
1155
- ast:: TraitItemKind :: Type ( ref _bounds , ref default_ty) => {
1147
+ ast:: TraitItemKind :: Type ( ref bounds , ref default_ty) => {
1156
1148
// FIXME do something with _bounds (for type refs)
1157
1149
let name = trait_item. ident . name . to_string ( ) ;
1158
1150
let qualname = format ! ( "::{}" , self . tcx. node_path_str( trait_item. id) ) ;
@@ -1168,7 +1160,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
1168
1160
visibility : Visibility :: Public ,
1169
1161
parent : Some ( trait_id) ,
1170
1162
docs : docs_for_attrs ( & trait_item. attrs ) ,
1171
- sig : None ,
1163
+ sig : sig:: assoc_type_signature ( trait_item. id ,
1164
+ trait_item. ident ,
1165
+ Some ( bounds) ,
1166
+ default_ty. as_ref ( ) . map ( |ty| & * * ty) ,
1167
+ & self . save_ctxt ) ,
1172
1168
attributes : trait_item. attrs . clone ( ) ,
1173
1169
} . lower ( self . tcx ) ) ;
1174
1170
}
@@ -1177,7 +1173,6 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
1177
1173
self . visit_ty ( default_ty)
1178
1174
}
1179
1175
}
1180
- ast:: TraitItemKind :: Const ( ref ty, None ) => self . visit_ty ( ty) ,
1181
1176
ast:: TraitItemKind :: Macro ( _) => { }
1182
1177
}
1183
1178
}
@@ -1190,7 +1185,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
1190
1185
impl_item. ident . name ,
1191
1186
impl_item. span ,
1192
1187
& ty,
1193
- & expr,
1188
+ Some ( expr) ,
1194
1189
impl_id,
1195
1190
From :: from ( & impl_item. vis ) ,
1196
1191
& impl_item. attrs ) ;
@@ -1199,12 +1194,17 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
1199
1194
self . process_method ( sig,
1200
1195
Some ( body) ,
1201
1196
impl_item. id ,
1202
- impl_item. ident . name ,
1197
+ impl_item. ident ,
1203
1198
From :: from ( & impl_item. vis ) ,
1204
1199
& impl_item. attrs ,
1205
1200
impl_item. span ) ;
1206
1201
}
1207
- ast:: ImplItemKind :: Type ( ref ty) => self . visit_ty ( ty) ,
1202
+ ast:: ImplItemKind :: Type ( ref ty) => {
1203
+ // FIXME uses of the assoc type should ideally point to this
1204
+ // 'def' and the name here should be a ref to the def in the
1205
+ // trait.
1206
+ self . visit_ty ( ty)
1207
+ }
1208
1208
ast:: ImplItemKind :: Macro ( _) => { }
1209
1209
}
1210
1210
}
@@ -1369,7 +1369,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
1369
1369
visibility : From :: from ( & item. vis ) ,
1370
1370
parent : None ,
1371
1371
docs : docs_for_attrs ( & item. attrs ) ,
1372
- sig : Some ( self . save_ctxt . sig_base ( item ) ) ,
1372
+ sig : sig :: item_signature ( item , & self . save_ctxt ) ,
1373
1373
attributes : item. attrs . clone ( ) ,
1374
1374
} . lower ( self . tcx ) ) ;
1375
1375
}
0 commit comments