forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexternal_data.rs
804 lines (718 loc) · 22 KB
/
external_data.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::hir::def_id::{CrateNum, DefId, DefIndex};
use rustc::hir::map::Map;
use rustc::ty::TyCtxt;
use syntax::ast::{self, NodeId};
use syntax::codemap::CodeMap;
use syntax::print::pprust;
use syntax::symbol::Symbol;
use syntax_pos::Span;
use data::{self, Visibility, SigElement};
// FIXME: this should be pub(crate), but the current snapshot doesn't allow it yet
pub trait Lower {
type Target;
fn lower(self, tcx: TyCtxt) -> Self::Target;
}
pub fn make_def_id(id: NodeId, map: &Map) -> DefId {
map.opt_local_def_id(id).unwrap_or(null_def_id())
}
pub fn null_def_id() -> DefId {
DefId {
krate: CrateNum::from_u32(u32::max_value()),
index: DefIndex::from_u32(u32::max_value())
}
}
#[derive(Clone, Debug, RustcEncodable)]
pub struct SpanData {
pub file_name: String,
pub byte_start: u32,
pub byte_end: u32,
/// 1-based.
pub line_start: usize,
pub line_end: usize,
/// 1-based, character offset.
pub column_start: usize,
pub column_end: usize,
}
impl SpanData {
pub fn from_span(span: Span, cm: &CodeMap) -> SpanData {
let start = cm.lookup_char_pos(span.lo);
let end = cm.lookup_char_pos(span.hi);
SpanData {
file_name: start.file.name.clone(),
byte_start: span.lo.0,
byte_end: span.hi.0,
line_start: start.line,
line_end: end.line,
column_start: start.col.0 + 1,
column_end: end.col.0 + 1,
}
}
}
/// Represent an arbitrary attribute on a code element
#[derive(Clone, Debug, RustcEncodable)]
pub struct Attribute {
value: String,
span: SpanData,
}
impl Lower for Vec<ast::Attribute> {
type Target = Vec<Attribute>;
fn lower(self, tcx: TyCtxt) -> Vec<Attribute> {
let doc = Symbol::intern("doc");
self.into_iter()
// Only retain real attributes. Doc comments are lowered separately.
.filter(|attr| attr.name() != doc)
.map(|mut attr| {
// Remove the surrounding '#[..]' or '#![..]' of the pretty printed
// attribute. First normalize all inner attribute (#![..]) to outer
// ones (#[..]), then remove the two leading and the one trailing character.
attr.style = ast::AttrStyle::Outer;
let value = pprust::attribute_to_string(&attr);
// This str slicing works correctly, because the leading and trailing characters
// are in the ASCII range and thus exactly one byte each.
let value = value[2..value.len()-1].to_string();
Attribute {
value: value,
span: SpanData::from_span(attr.span, tcx.sess.codemap()),
}
}).collect()
}
}
#[derive(Debug, RustcEncodable)]
pub struct CratePreludeData {
pub crate_name: String,
pub crate_root: String,
pub external_crates: Vec<data::ExternalCrateData>,
pub span: SpanData,
}
impl Lower for data::CratePreludeData {
type Target = CratePreludeData;
fn lower(self, tcx: TyCtxt) -> CratePreludeData {
CratePreludeData {
crate_name: self.crate_name,
crate_root: self.crate_root,
external_crates: self.external_crates,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
}
}
}
/// Data for enum declarations.
#[derive(Clone, Debug, RustcEncodable)]
pub struct EnumData {
pub id: DefId,
pub value: String,
pub name: String,
pub qualname: String,
pub span: SpanData,
pub scope: DefId,
pub variants: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub attributes: Vec<Attribute>,
}
impl Lower for data::EnumData {
type Target = EnumData;
fn lower(self, tcx: TyCtxt) -> EnumData {
EnumData {
id: make_def_id(self.id, &tcx.hir),
name: self.name,
value: self.value,
qualname: self.qualname,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
attributes: self.attributes.lower(tcx),
}
}
}
/// Data for extern crates.
#[derive(Debug, RustcEncodable)]
pub struct ExternCrateData {
pub id: DefId,
pub name: String,
pub crate_num: CrateNum,
pub location: String,
pub span: SpanData,
pub scope: DefId,
}
impl Lower for data::ExternCrateData {
type Target = ExternCrateData;
fn lower(self, tcx: TyCtxt) -> ExternCrateData {
ExternCrateData {
id: make_def_id(self.id, &tcx.hir),
name: self.name,
crate_num: self.crate_num,
location: self.location,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
}
}
}
/// Data about a function call.
#[derive(Debug, RustcEncodable)]
pub struct FunctionCallData {
pub span: SpanData,
pub scope: DefId,
pub ref_id: DefId,
}
impl Lower for data::FunctionCallData {
type Target = FunctionCallData;
fn lower(self, tcx: TyCtxt) -> FunctionCallData {
FunctionCallData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
}
}
}
/// Data for all kinds of functions and methods.
#[derive(Clone, Debug, RustcEncodable)]
pub struct FunctionData {
pub id: DefId,
pub name: String,
pub qualname: String,
pub declaration: Option<DefId>,
pub span: SpanData,
pub scope: DefId,
pub value: String,
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub attributes: Vec<Attribute>,
}
impl Lower for data::FunctionData {
type Target = FunctionData;
fn lower(self, tcx: TyCtxt) -> FunctionData {
FunctionData {
id: make_def_id(self.id, &tcx.hir),
name: self.name,
qualname: self.qualname,
declaration: self.declaration,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
value: self.value,
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
attributes: self.attributes.lower(tcx),
}
}
}
/// Data about a function call.
#[derive(Debug, RustcEncodable)]
pub struct FunctionRefData {
pub span: SpanData,
pub scope: DefId,
pub ref_id: DefId,
}
impl Lower for data::FunctionRefData {
type Target = FunctionRefData;
fn lower(self, tcx: TyCtxt) -> FunctionRefData {
FunctionRefData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
}
}
}
#[derive(Debug, RustcEncodable)]
pub struct ImplData {
pub id: DefId,
pub span: SpanData,
pub scope: DefId,
pub trait_ref: Option<DefId>,
pub self_ref: Option<DefId>,
}
impl Lower for data::ImplData {
type Target = ImplData;
fn lower(self, tcx: TyCtxt) -> ImplData {
ImplData {
id: make_def_id(self.id, &tcx.hir),
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
trait_ref: self.trait_ref,
self_ref: self.self_ref,
}
}
}
#[derive(Debug, RustcEncodable)]
pub struct InheritanceData {
pub span: SpanData,
pub base_id: DefId,
pub deriv_id: DefId
}
impl Lower for data::InheritanceData {
type Target = InheritanceData;
fn lower(self, tcx: TyCtxt) -> InheritanceData {
InheritanceData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
base_id: self.base_id,
deriv_id: make_def_id(self.deriv_id, &tcx.hir)
}
}
}
/// Data about a macro declaration.
#[derive(Debug, RustcEncodable)]
pub struct MacroData {
pub span: SpanData,
pub name: String,
pub qualname: String,
pub docs: String,
}
impl Lower for data::MacroData {
type Target = MacroData;
fn lower(self, tcx: TyCtxt) -> MacroData {
MacroData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
qualname: self.qualname,
docs: self.docs,
}
}
}
/// Data about a macro use.
#[derive(Debug, RustcEncodable)]
pub struct MacroUseData {
pub span: SpanData,
pub name: String,
pub qualname: String,
// Because macro expansion happens before ref-ids are determined,
// we use the callee span to reference the associated macro definition.
pub callee_span: SpanData,
pub scope: DefId,
}
impl Lower for data::MacroUseData {
type Target = MacroUseData;
fn lower(self, tcx: TyCtxt) -> MacroUseData {
MacroUseData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
qualname: self.qualname,
callee_span: SpanData::from_span(self.callee_span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
}
}
}
/// Data about a method call.
#[derive(Debug, RustcEncodable)]
pub struct MethodCallData {
pub span: SpanData,
pub scope: DefId,
pub ref_id: Option<DefId>,
pub decl_id: Option<DefId>,
}
impl Lower for data::MethodCallData {
type Target = MethodCallData;
fn lower(self, tcx: TyCtxt) -> MethodCallData {
MethodCallData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
decl_id: self.decl_id,
}
}
}
/// Data for method declarations (methods with a body are treated as functions).
#[derive(Clone, Debug, RustcEncodable)]
pub struct MethodData {
pub id: DefId,
pub name: String,
pub qualname: String,
pub span: SpanData,
pub scope: DefId,
pub value: String,
pub decl_id: Option<DefId>,
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub attributes: Vec<Attribute>,
}
impl Lower for data::MethodData {
type Target = MethodData;
fn lower(self, tcx: TyCtxt) -> MethodData {
MethodData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
scope: make_def_id(self.scope, &tcx.hir),
id: make_def_id(self.id, &tcx.hir),
qualname: self.qualname,
value: self.value,
decl_id: self.decl_id,
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
attributes: self.attributes.lower(tcx),
}
}
}
/// Data for modules.
#[derive(Debug, RustcEncodable)]
pub struct ModData {
pub id: DefId,
pub name: String,
pub qualname: String,
pub span: SpanData,
pub scope: DefId,
pub filename: String,
pub items: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub attributes: Vec<Attribute>,
}
impl Lower for data::ModData {
type Target = ModData;
fn lower(self, tcx: TyCtxt) -> ModData {
ModData {
id: make_def_id(self.id, &tcx.hir),
name: self.name,
qualname: self.qualname,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
filename: self.filename,
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
attributes: self.attributes.lower(tcx),
}
}
}
/// Data for a reference to a module.
#[derive(Debug, RustcEncodable)]
pub struct ModRefData {
pub span: SpanData,
pub scope: DefId,
pub ref_id: Option<DefId>,
pub qualname: String
}
impl Lower for data::ModRefData {
type Target = ModRefData;
fn lower(self, tcx: TyCtxt) -> ModRefData {
ModRefData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
qualname: self.qualname,
}
}
}
#[derive(Debug, RustcEncodable)]
pub struct StructData {
pub span: SpanData,
pub name: String,
pub id: DefId,
pub ctor_id: DefId,
pub qualname: String,
pub scope: DefId,
pub value: String,
pub fields: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub attributes: Vec<Attribute>,
}
impl Lower for data::StructData {
type Target = StructData;
fn lower(self, tcx: TyCtxt) -> StructData {
StructData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
id: make_def_id(self.id, &tcx.hir),
ctor_id: make_def_id(self.ctor_id, &tcx.hir),
qualname: self.qualname,
scope: make_def_id(self.scope, &tcx.hir),
value: self.value,
fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
attributes: self.attributes.lower(tcx),
}
}
}
#[derive(Debug, RustcEncodable)]
pub struct StructVariantData {
pub span: SpanData,
pub name: String,
pub id: DefId,
pub qualname: String,
pub type_value: String,
pub value: String,
pub scope: DefId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub attributes: Vec<Attribute>,
}
impl Lower for data::StructVariantData {
type Target = StructVariantData;
fn lower(self, tcx: TyCtxt) -> StructVariantData {
StructVariantData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
id: make_def_id(self.id, &tcx.hir),
qualname: self.qualname,
type_value: self.type_value,
value: self.value,
scope: make_def_id(self.scope, &tcx.hir),
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
attributes: self.attributes.lower(tcx),
}
}
}
#[derive(Debug, RustcEncodable)]
pub struct TraitData {
pub span: SpanData,
pub name: String,
pub id: DefId,
pub qualname: String,
pub scope: DefId,
pub value: String,
pub items: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub attributes: Vec<Attribute>,
}
impl Lower for data::TraitData {
type Target = TraitData;
fn lower(self, tcx: TyCtxt) -> TraitData {
TraitData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
id: make_def_id(self.id, &tcx.hir),
qualname: self.qualname,
scope: make_def_id(self.scope, &tcx.hir),
value: self.value,
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
attributes: self.attributes.lower(tcx),
}
}
}
#[derive(Debug, RustcEncodable)]
pub struct TupleVariantData {
pub span: SpanData,
pub id: DefId,
pub name: String,
pub qualname: String,
pub type_value: String,
pub value: String,
pub scope: DefId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub attributes: Vec<Attribute>,
}
impl Lower for data::TupleVariantData {
type Target = TupleVariantData;
fn lower(self, tcx: TyCtxt) -> TupleVariantData {
TupleVariantData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
id: make_def_id(self.id, &tcx.hir),
name: self.name,
qualname: self.qualname,
type_value: self.type_value,
value: self.value,
scope: make_def_id(self.scope, &tcx.hir),
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
attributes: self.attributes.lower(tcx),
}
}
}
/// Data for a typedef.
#[derive(Debug, RustcEncodable)]
pub struct TypeDefData {
pub id: DefId,
pub name: String,
pub span: SpanData,
pub qualname: String,
pub value: String,
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
impl Lower for data::TypeDefData {
type Target = TypeDefData;
fn lower(self, tcx: TyCtxt) -> TypeDefData {
TypeDefData {
id: make_def_id(self.id, &tcx.hir),
name: self.name,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
qualname: self.qualname,
value: self.value,
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.map(|s| s.lower(tcx)),
attributes: self.attributes.lower(tcx),
}
}
}
/// Data for a reference to a type or trait.
#[derive(Clone, Debug, RustcEncodable)]
pub struct TypeRefData {
pub span: SpanData,
pub scope: DefId,
pub ref_id: Option<DefId>,
pub qualname: String,
}
impl Lower for data::TypeRefData {
type Target = TypeRefData;
fn lower(self, tcx: TyCtxt) -> TypeRefData {
TypeRefData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
qualname: self.qualname,
}
}
}
#[derive(Debug, RustcEncodable)]
pub struct UseData {
pub id: DefId,
pub span: SpanData,
pub name: String,
pub mod_id: Option<DefId>,
pub scope: DefId,
pub visibility: Visibility,
}
impl Lower for data::UseData {
type Target = UseData;
fn lower(self, tcx: TyCtxt) -> UseData {
UseData {
id: make_def_id(self.id, &tcx.hir),
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
mod_id: self.mod_id,
scope: make_def_id(self.scope, &tcx.hir),
visibility: self.visibility,
}
}
}
#[derive(Debug, RustcEncodable)]
pub struct UseGlobData {
pub id: DefId,
pub span: SpanData,
pub names: Vec<String>,
pub scope: DefId,
pub visibility: Visibility,
}
impl Lower for data::UseGlobData {
type Target = UseGlobData;
fn lower(self, tcx: TyCtxt) -> UseGlobData {
UseGlobData {
id: make_def_id(self.id, &tcx.hir),
span: SpanData::from_span(self.span, tcx.sess.codemap()),
names: self.names,
scope: make_def_id(self.scope, &tcx.hir),
visibility: self.visibility,
}
}
}
/// Data for local and global variables (consts and statics).
#[derive(Debug, RustcEncodable)]
pub struct VariableData {
pub id: DefId,
pub name: String,
pub kind: data::VariableKind,
pub qualname: String,
pub span: SpanData,
pub scope: DefId,
pub value: String,
pub type_value: String,
pub parent: Option<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
impl Lower for data::VariableData {
type Target = VariableData;
fn lower(self, tcx: TyCtxt) -> VariableData {
VariableData {
id: make_def_id(self.id, &tcx.hir),
kind: self.kind,
name: self.name,
qualname: self.qualname,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
value: self.value,
type_value: self.type_value,
parent: self.parent,
visibility: self.visibility,
docs: self.docs,
sig: self.sig.map(|s| s.lower(tcx)),
attributes: self.attributes.lower(tcx),
}
}
}
/// Data for the use of some item (e.g., the use of a local variable, which
/// will refer to that variables declaration (by ref_id)).
#[derive(Debug, RustcEncodable)]
pub struct VariableRefData {
pub name: String,
pub span: SpanData,
pub scope: DefId,
pub ref_id: DefId,
}
impl Lower for data::VariableRefData {
type Target = VariableRefData;
fn lower(self, tcx: TyCtxt) -> VariableRefData {
VariableRefData {
name: self.name,
span: SpanData::from_span(self.span, tcx.sess.codemap()),
scope: make_def_id(self.scope, &tcx.hir),
ref_id: self.ref_id,
}
}
}
#[derive(Clone, Debug, RustcEncodable)]
pub struct Signature {
pub span: SpanData,
pub text: String,
// These identify the main identifier for the defintion as byte offsets into
// `text`. E.g., of `foo` in `pub fn foo(...)`
pub ident_start: usize,
pub ident_end: usize,
pub defs: Vec<SigElement>,
pub refs: Vec<SigElement>,
}
impl Lower for data::Signature {
type Target = Signature;
fn lower(self, tcx: TyCtxt) -> Signature {
Signature {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
text: self.text,
ident_start: self.ident_start,
ident_end: self.ident_end,
defs: self.defs,
refs: self.refs,
}
}
}