2016-04-25 03:54:00 -05:00
|
|
|
// 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 std::io::Write;
|
|
|
|
|
2016-05-11 11:59:35 -05:00
|
|
|
use rustc::hir::def_id::DefId;
|
2016-04-25 03:54:00 -05:00
|
|
|
use rustc_serialize::json::as_json;
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
use rls_data::{self, Id, Analysis, Import, ImportKind, Def, DefKind, Ref, RefKind, MacroRef,
|
|
|
|
Relation, RelationKind, Signature, SigElement, CratePreludeData};
|
|
|
|
|
|
|
|
use external_data;
|
2016-06-11 05:23:57 -05:00
|
|
|
use external_data::*;
|
2017-03-13 23:08:47 -05:00
|
|
|
use data::{self, VariableKind};
|
2016-06-11 05:23:57 -05:00
|
|
|
use dump::Dump;
|
2016-09-06 18:28:13 -05:00
|
|
|
use super::Format;
|
2016-04-25 03:54:00 -05:00
|
|
|
|
2016-05-03 05:54:29 -05:00
|
|
|
pub struct JsonDumper<'b, W: Write + 'b> {
|
2016-04-25 03:54:00 -05:00
|
|
|
output: &'b mut W,
|
2016-05-11 11:59:35 -05:00
|
|
|
result: Analysis,
|
2016-04-25 03:54:00 -05:00
|
|
|
}
|
|
|
|
|
2016-05-03 05:54:29 -05:00
|
|
|
impl<'b, W: Write> JsonDumper<'b, W> {
|
|
|
|
pub fn new(writer: &'b mut W) -> JsonDumper<'b, W> {
|
2016-05-11 11:59:35 -05:00
|
|
|
JsonDumper { output: writer, result: Analysis::new() }
|
2016-04-25 17:14:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 05:54:29 -05:00
|
|
|
impl<'b, W: Write> Drop for JsonDumper<'b, W> {
|
2016-04-25 17:14:44 -05:00
|
|
|
fn drop(&mut self) {
|
2016-05-11 11:59:35 -05:00
|
|
|
if let Err(_) = write!(self.output, "{}", as_json(&self.result)) {
|
2016-04-25 17:14:44 -05:00
|
|
|
error!("Error writing output");
|
|
|
|
}
|
2016-04-25 03:54:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_fn {
|
2016-05-12 18:29:07 -05:00
|
|
|
($fn_name: ident, $data_type: ident, $bucket: ident) => {
|
2016-05-03 05:54:29 -05:00
|
|
|
fn $fn_name(&mut self, data: $data_type) {
|
2017-03-13 23:08:47 -05:00
|
|
|
self.result.$bucket.push(data.into());
|
2016-04-25 05:53:01 -05:00
|
|
|
}
|
2016-04-25 03:54:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 05:54:29 -05:00
|
|
|
impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> {
|
2016-05-11 11:59:35 -05:00
|
|
|
fn crate_prelude(&mut self, data: CratePreludeData) {
|
|
|
|
self.result.prelude = Some(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_fn!(extern_crate, ExternCrateData, imports);
|
|
|
|
impl_fn!(use_data, UseData, imports);
|
|
|
|
impl_fn!(use_glob, UseGlobData, imports);
|
|
|
|
|
|
|
|
impl_fn!(enum_data, EnumData, defs);
|
|
|
|
impl_fn!(tuple_variant, TupleVariantData, defs);
|
|
|
|
impl_fn!(struct_variant, StructVariantData, defs);
|
|
|
|
impl_fn!(struct_data, StructData, defs);
|
|
|
|
impl_fn!(trait_data, TraitData, defs);
|
|
|
|
impl_fn!(function, FunctionData, defs);
|
|
|
|
impl_fn!(method, MethodData, defs);
|
|
|
|
impl_fn!(macro_data, MacroData, defs);
|
|
|
|
impl_fn!(typedef, TypeDefData, defs);
|
|
|
|
impl_fn!(variable, VariableData, defs);
|
|
|
|
|
|
|
|
impl_fn!(function_ref, FunctionRefData, refs);
|
|
|
|
impl_fn!(function_call, FunctionCallData, refs);
|
|
|
|
impl_fn!(method_call, MethodCallData, refs);
|
|
|
|
impl_fn!(mod_ref, ModRefData, refs);
|
|
|
|
impl_fn!(type_ref, TypeRefData, refs);
|
|
|
|
impl_fn!(variable_ref, VariableRefData, refs);
|
|
|
|
|
|
|
|
impl_fn!(macro_use, MacroUseData, macro_refs);
|
|
|
|
|
2016-11-24 21:50:47 -06:00
|
|
|
fn mod_data(&mut self, data: ModData) {
|
2017-03-13 23:08:47 -05:00
|
|
|
let id: Id = id_from_def_id(data.id);
|
2016-11-24 21:50:47 -06:00
|
|
|
let mut def = Def {
|
|
|
|
kind: DefKind::Mod,
|
|
|
|
id: id,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: data.span.into(),
|
2016-11-24 21:50:47 -06:00
|
|
|
name: data.name,
|
|
|
|
qualname: data.qualname,
|
|
|
|
value: data.filename,
|
2017-03-13 23:08:47 -05:00
|
|
|
parent: None,
|
|
|
|
children: data.items.into_iter().map(|id| id_from_def_id(id)).collect(),
|
2016-11-24 21:50:47 -06:00
|
|
|
decl_id: None,
|
|
|
|
docs: data.docs,
|
2017-03-13 23:08:47 -05:00
|
|
|
sig: Some(data.sig.into()),
|
|
|
|
attributes: data.attributes.into_iter().map(|a| a.into()).collect(),
|
2016-11-24 21:50:47 -06:00
|
|
|
};
|
2017-03-13 23:08:47 -05:00
|
|
|
if data.span.file_name.to_str().unwrap() != def.value {
|
2016-11-24 21:50:47 -06:00
|
|
|
// If the module is an out-of-line defintion, then we'll make the
|
|
|
|
// defintion the first character in the module's file and turn the
|
|
|
|
// the declaration into a reference to it.
|
|
|
|
let rf = Ref {
|
|
|
|
kind: RefKind::Mod,
|
|
|
|
span: def.span,
|
|
|
|
ref_id: id,
|
|
|
|
};
|
|
|
|
self.result.refs.push(rf);
|
2017-03-13 23:08:47 -05:00
|
|
|
def.span = rls_data::SpanData {
|
|
|
|
file_name: def.value.clone().into(),
|
2016-11-24 21:50:47 -06:00
|
|
|
byte_start: 0,
|
|
|
|
byte_end: 0,
|
|
|
|
line_start: 1,
|
|
|
|
line_end: 1,
|
|
|
|
column_start: 1,
|
|
|
|
column_end: 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.result.defs.push(def);
|
|
|
|
}
|
|
|
|
|
2017-02-12 22:50:58 -06:00
|
|
|
fn impl_data(&mut self, data: ImplData) {
|
|
|
|
if data.self_ref.is_some() {
|
2017-03-13 23:08:47 -05:00
|
|
|
self.result.relations.push(data.into());
|
2017-02-12 22:50:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn inheritance(&mut self, data: InheritanceData) {
|
2017-03-13 23:08:47 -05:00
|
|
|
self.result.relations.push(data.into());
|
2017-02-12 22:50:58 -06:00
|
|
|
}
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME do we want to change ExternalData to this mode? It will break DXR.
|
|
|
|
// FIXME methods. The defs have information about possible overriding and the
|
|
|
|
// refs have decl information (e.g., a trait method where we know the required
|
|
|
|
// method, but not the supplied method). In both cases, we are currently
|
|
|
|
// ignoring it.
|
|
|
|
|
2016-05-12 18:29:07 -05:00
|
|
|
// DefId::index is a newtype and so the JSON serialisation is ugly. Therefore
|
|
|
|
// we use our own Id which is the same, but without the newtype.
|
2017-03-13 23:08:47 -05:00
|
|
|
fn id_from_def_id(id: DefId) -> Id {
|
|
|
|
Id {
|
|
|
|
krate: id.krate.as_u32(),
|
|
|
|
index: id.index.as_u32(),
|
|
|
|
}
|
2016-05-12 18:29:07 -05:00
|
|
|
}
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Import> for ExternCrateData {
|
|
|
|
fn into(self) -> Import {
|
2016-05-11 11:59:35 -05:00
|
|
|
Import {
|
|
|
|
kind: ImportKind::ExternCrate,
|
2016-10-28 17:24:37 -05:00
|
|
|
ref_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
2016-05-11 11:59:35 -05:00
|
|
|
value: String::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Import> for UseData {
|
|
|
|
fn into(self) -> Import {
|
2016-05-11 11:59:35 -05:00
|
|
|
Import {
|
|
|
|
kind: ImportKind::Use,
|
2017-03-13 23:08:47 -05:00
|
|
|
ref_id: self.mod_id.map(|id| id_from_def_id(id)),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
2016-05-11 11:59:35 -05:00
|
|
|
value: String::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Import> for UseGlobData {
|
|
|
|
fn into(self) -> Import {
|
2016-05-11 11:59:35 -05:00
|
|
|
Import {
|
|
|
|
kind: ImportKind::GlobUse,
|
2016-10-28 17:24:37 -05:00
|
|
|
ref_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
2016-05-11 11:59:35 -05:00
|
|
|
name: "*".to_owned(),
|
2017-03-13 23:08:47 -05:00
|
|
|
value: self.names.join(", "),
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for EnumData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Enum,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
parent: None,
|
|
|
|
children: self.variants.into_iter().map(|id| id_from_def_id(id)).collect(),
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
docs: self.docs,
|
|
|
|
sig: Some(self.sig.into()),
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for TupleVariantData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Tuple,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
parent: None,
|
2016-06-11 05:23:57 -05:00
|
|
|
children: vec![],
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
docs: self.docs,
|
|
|
|
sig: Some(self.sig.into()),
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for StructVariantData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Struct,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
parent: None,
|
2016-06-11 05:23:57 -05:00
|
|
|
children: vec![],
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
docs: self.docs,
|
|
|
|
sig: Some(self.sig.into()),
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for StructData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Struct,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
parent: None,
|
|
|
|
children: self.fields.into_iter().map(|id| id_from_def_id(id)).collect(),
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
docs: self.docs,
|
|
|
|
sig: Some(self.sig.into()),
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for TraitData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Trait,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
parent: None,
|
|
|
|
children: self.items.into_iter().map(|id| id_from_def_id(id)).collect(),
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
docs: self.docs,
|
|
|
|
sig: Some(self.sig.into()),
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for FunctionData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Function,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
parent: None,
|
2016-06-11 05:23:57 -05:00
|
|
|
children: vec![],
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
docs: self.docs,
|
|
|
|
sig: Some(self.sig.into()),
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for MethodData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
2016-06-11 05:23:57 -05:00
|
|
|
kind: DefKind::Method,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
parent: None,
|
2016-06-11 05:23:57 -05:00
|
|
|
children: vec![],
|
2017-03-13 23:08:47 -05:00
|
|
|
decl_id: self.decl_id.map(|id| id_from_def_id(id)),
|
|
|
|
docs: self.docs,
|
|
|
|
sig: Some(self.sig.into()),
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for MacroData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Macro,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(null_def_id()),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
2016-05-11 11:59:35 -05:00
|
|
|
value: String::new(),
|
2017-03-13 23:08:47 -05:00
|
|
|
parent: None,
|
2016-06-11 05:23:57 -05:00
|
|
|
children: vec![],
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
docs: self.docs,
|
2016-11-29 16:50:08 -06:00
|
|
|
sig: None,
|
2017-02-14 04:05:53 -06:00
|
|
|
attributes: vec![],
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for TypeDefData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Type,
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
parent: None,
|
2016-06-11 05:23:57 -05:00
|
|
|
children: vec![],
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2016-09-06 18:23:49 -05:00
|
|
|
docs: String::new(),
|
2017-03-13 23:08:47 -05:00
|
|
|
sig: self.sig.map(|s| s.into()),
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Def> for VariableData {
|
|
|
|
fn into(self) -> Def {
|
2016-05-11 11:59:35 -05:00
|
|
|
Def {
|
2017-03-13 23:08:47 -05:00
|
|
|
kind: match self.kind {
|
2016-06-11 05:23:57 -05:00
|
|
|
VariableKind::Static => DefKind::Static,
|
|
|
|
VariableKind::Const => DefKind::Const,
|
|
|
|
VariableKind::Local => DefKind::Local,
|
|
|
|
VariableKind::Field => DefKind::Field,
|
|
|
|
},
|
2017-03-13 23:08:47 -05:00
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
span: self.span,
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.type_value,
|
|
|
|
parent: None,
|
2016-06-11 05:23:57 -05:00
|
|
|
children: vec![],
|
2016-06-16 05:28:39 -05:00
|
|
|
decl_id: None,
|
2017-03-13 23:08:47 -05:00
|
|
|
docs: self.docs,
|
2016-11-20 12:07:40 -06:00
|
|
|
sig: None,
|
2017-03-14 14:58:04 -05:00
|
|
|
attributes: self.attributes,
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Ref> for FunctionRefData {
|
|
|
|
fn into(self) -> Ref {
|
2016-05-11 11:59:35 -05:00
|
|
|
Ref {
|
|
|
|
kind: RefKind::Function,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
|
|
|
ref_id: id_from_def_id(self.ref_id),
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Ref> for FunctionCallData {
|
|
|
|
fn into(self) -> Ref {
|
2016-05-11 11:59:35 -05:00
|
|
|
Ref {
|
|
|
|
kind: RefKind::Function,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
|
|
|
ref_id: id_from_def_id(self.ref_id),
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Ref> for MethodCallData {
|
|
|
|
fn into(self) -> Ref {
|
2016-05-11 11:59:35 -05:00
|
|
|
Ref {
|
|
|
|
kind: RefKind::Function,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
|
|
|
ref_id: id_from_def_id(self.ref_id.or(self.decl_id).unwrap_or(null_def_id())),
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Ref> for ModRefData {
|
|
|
|
fn into(self) -> Ref {
|
2016-05-11 11:59:35 -05:00
|
|
|
Ref {
|
|
|
|
kind: RefKind::Mod,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
|
|
|
ref_id: id_from_def_id(self.ref_id.unwrap_or(null_def_id())),
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Ref> for TypeRefData {
|
|
|
|
fn into(self) -> Ref {
|
2016-05-11 11:59:35 -05:00
|
|
|
Ref {
|
|
|
|
kind: RefKind::Type,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
|
|
|
ref_id: id_from_def_id(self.ref_id.unwrap_or(null_def_id())),
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Ref> for VariableRefData {
|
|
|
|
fn into(self) -> Ref {
|
2016-05-11 11:59:35 -05:00
|
|
|
Ref {
|
|
|
|
kind: RefKind::Variable,
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
|
|
|
ref_id: id_from_def_id(self.ref_id),
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<MacroRef> for MacroUseData {
|
|
|
|
fn into(self) -> MacroRef {
|
2016-05-11 11:59:35 -05:00
|
|
|
MacroRef {
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
|
|
|
qualname: self.qualname,
|
|
|
|
callee_span: self.callee_span.into(),
|
2016-05-11 11:59:35 -05:00
|
|
|
}
|
|
|
|
}
|
2016-04-25 03:54:00 -05:00
|
|
|
}
|
2016-11-21 15:05:25 -06:00
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Relation> for ImplData {
|
|
|
|
fn into(self) -> Relation {
|
2017-02-12 22:50:58 -06:00
|
|
|
Relation {
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
2017-02-12 22:50:58 -06:00
|
|
|
kind: RelationKind::Impl,
|
2017-03-13 23:08:47 -05:00
|
|
|
from: id_from_def_id(self.self_ref.unwrap_or(null_def_id())),
|
|
|
|
to: id_from_def_id(self.trait_ref.unwrap_or(null_def_id())),
|
2017-02-12 22:50:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Relation> for InheritanceData {
|
|
|
|
fn into(self) -> Relation {
|
2017-02-12 22:50:58 -06:00
|
|
|
Relation {
|
2017-03-13 23:08:47 -05:00
|
|
|
span: self.span,
|
2017-02-12 22:50:58 -06:00
|
|
|
kind: RelationKind::SuperTrait,
|
2017-03-13 23:08:47 -05:00
|
|
|
from: id_from_def_id(self.base_id),
|
|
|
|
to: id_from_def_id(self.deriv_id),
|
2017-02-12 22:50:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<Signature> for external_data::Signature {
|
|
|
|
fn into(self) -> Signature {
|
|
|
|
Signature {
|
|
|
|
span: self.span,
|
|
|
|
text: self.text,
|
|
|
|
ident_start: self.ident_start,
|
|
|
|
ident_end: self.ident_end,
|
|
|
|
defs: self.defs.into_iter().map(|s| s.into()).collect(),
|
|
|
|
refs: self.refs.into_iter().map(|s| s.into()).collect(),
|
2016-11-21 15:05:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:08:47 -05:00
|
|
|
impl Into<SigElement> for data::SigElement {
|
|
|
|
fn into(self) -> SigElement {
|
|
|
|
SigElement {
|
|
|
|
id: id_from_def_id(self.id),
|
|
|
|
start: self.start,
|
|
|
|
end: self.end,
|
2016-11-21 15:05:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|