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