Skip to content

save-analysis: redirect a module decl to the start of the defining file #37989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions src/librustc_save_analysis/json_dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> {
impl_fn!(function, FunctionData, defs);
impl_fn!(method, MethodData, defs);
impl_fn!(macro_data, MacroData, defs);
impl_fn!(mod_data, ModData, defs);
impl_fn!(typedef, TypeDefData, defs);
impl_fn!(variable, VariableData, defs);

Expand All @@ -75,6 +74,43 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> {

impl_fn!(macro_use, MacroUseData, macro_refs);

fn mod_data(&mut self, data: ModData) {
let id: Id = From::from(data.id);
let mut def = Def {
kind: DefKind::Mod,
id: id,
span: data.span,
name: data.name,
qualname: data.qualname,
value: data.filename,
children: data.items.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
};
if def.span.file_name != def.value {
// 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);
def.span = SpanData {
file_name: def.value.clone(),
byte_start: 0,
byte_end: 0,
line_start: 1,
line_end: 1,
column_start: 1,
column_end: 1,
}
}

self.result.defs.push(def);
}

// FIXME store this instead of throwing it away.
fn impl_data(&mut self, _data: ImplData) {}
fn inheritance(&mut self, _data: InheritanceData) {}
Expand Down Expand Up @@ -111,7 +147,7 @@ impl Analysis {

// 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.
#[derive(Debug, RustcEncodable)]
#[derive(Clone, Copy, Debug, RustcEncodable)]
struct Id {
krate: u32,
index: u32,
Expand Down Expand Up @@ -337,21 +373,7 @@ impl From<MacroData> for Def {
}
}
}
impl From<ModData> for Def {
fn from(data:ModData) -> Def {
Def {
kind: DefKind::Mod,
id: From::from(data.id),
span: data.span,
name: data.name,
qualname: data.qualname,
value: data.filename,
children: data.items.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
}
}
}

impl From<TypeDefData> for Def {
fn from(data: TypeDefData) -> Def {
Def {
Expand Down