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