27
27
use rustc:: hir:: def:: Def as HirDef ;
28
28
use rustc:: hir:: def_id:: DefId ;
29
29
use rustc:: hir:: map:: Node ;
30
- use rustc:: session:: Session ;
31
30
use rustc:: ty:: { self , TyCtxt } ;
32
31
use rustc_data_structures:: fx:: FxHashSet ;
33
32
@@ -62,7 +61,6 @@ macro_rules! down_cast_data {
62
61
63
62
pub struct DumpVisitor < ' l , ' tcx : ' l , ' ll , O : DumpOutput + ' ll > {
64
63
save_ctxt : SaveContext < ' l , ' tcx > ,
65
- sess : & ' l Session ,
66
64
tcx : TyCtxt < ' l , ' tcx , ' tcx > ,
67
65
dumper : & ' ll mut JsonDumper < O > ,
68
66
@@ -84,7 +82,6 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
84
82
-> DumpVisitor < ' l , ' tcx , ' ll , O > {
85
83
let span_utils = SpanUtils :: new ( & save_ctxt. tcx . sess ) ;
86
84
DumpVisitor {
87
- sess : & save_ctxt. tcx . sess ,
88
85
tcx : save_ctxt. tcx ,
89
86
save_ctxt : save_ctxt,
90
87
dumper : dumper,
@@ -147,47 +144,23 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
147
144
// For each prefix, we return the span for the last segment in the prefix and
148
145
// a str representation of the entire prefix.
149
146
fn process_path_prefixes ( & self , path : & ast:: Path ) -> Vec < ( Span , String ) > {
150
- let spans = self . span . spans_for_path_segments ( path) ;
151
147
let segments = & path. segments [ if path. is_global ( ) { 1 } else { 0 } ..] ;
152
148
153
- // Paths to enums seem to not match their spans - the span includes all the
154
- // variants too. But they seem to always be at the end, so I hope we can cope with
155
- // always using the first ones. So, only error out if we don't have enough spans.
156
- // What could go wrong...?
157
- if spans. len ( ) < segments. len ( ) {
158
- if generated_code ( path. span ) {
159
- return vec ! [ ] ;
160
- }
161
- error ! ( "Mis-calculated spans for path '{}'. Found {} spans, expected {}. Found spans:" ,
162
- path_to_string( path) ,
163
- spans. len( ) ,
164
- segments. len( ) ) ;
165
- for s in & spans {
166
- let loc = self . sess . codemap ( ) . lookup_char_pos ( s. lo ) ;
167
- error ! ( " '{}' in {}, line {}" ,
168
- self . span. snippet( * s) ,
169
- loc. file. name,
170
- loc. line) ;
171
- }
172
- error ! ( " master span: {:?}: `{}`" , path. span, self . span. snippet( path. span) ) ;
173
- return vec ! [ ] ;
174
- }
175
-
176
- let mut result: Vec < ( Span , String ) > = vec ! [ ] ;
149
+ let mut result = Vec :: with_capacity ( segments. len ( ) ) ;
177
150
178
151
let mut segs = vec ! [ ] ;
179
- for ( i, ( seg, span ) ) in segments. iter ( ) . zip ( & spans ) . enumerate ( ) {
152
+ for ( i, seg) in segments. iter ( ) . enumerate ( ) {
180
153
segs. push ( seg. clone ( ) ) ;
181
154
let sub_path = ast:: Path {
182
- span : * span, // span for the last segment
155
+ span : seg . span , // span for the last segment
183
156
segments : segs,
184
157
} ;
185
158
let qualname = if i == 0 && path. is_global ( ) {
186
159
format ! ( "::{}" , path_to_string( & sub_path) )
187
160
} else {
188
161
path_to_string ( & sub_path)
189
162
} ;
190
- result. push ( ( * span, qualname) ) ;
163
+ result. push ( ( seg . span , qualname) ) ;
191
164
segs = sub_path. segments ;
192
165
}
193
166
@@ -437,13 +410,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
437
410
full_span : Span ,
438
411
prefix : & str ,
439
412
id : NodeId ) {
440
- // We can't only use visit_generics since we don't have spans for param
441
- // bindings, so we reparse the full_span to get those sub spans.
442
- // However full span is the entire enum/fn/struct block, so we only want
443
- // the first few to match the number of generics we're looking for.
444
- let param_sub_spans = self . span . spans_for_ty_params ( full_span,
445
- ( generics. ty_params . len ( ) as isize ) ) ;
446
- for ( param, param_ss) in generics. ty_params . iter ( ) . zip ( param_sub_spans) {
413
+ for param in & generics. ty_params {
414
+ let param_ss = param. span ;
447
415
let name = escape ( self . span . snippet ( param_ss) ) ;
448
416
// Append $id to name to make sure each one is unique
449
417
let qualname = format ! ( "{}::{}${}" ,
0 commit comments