Skip to content

Commit 5db4826

Browse files
committed
Auto merge of #37989 - nrc:save-mod, r=nikomatsakis
save-analysis: redirect a module decl to the start of the defining file
2 parents 3abaf43 + 5787643 commit 5db4826

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

src/librustc_save_analysis/json_dumper.rs

+39-17
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> {
6262
impl_fn!(function, FunctionData, defs);
6363
impl_fn!(method, MethodData, defs);
6464
impl_fn!(macro_data, MacroData, defs);
65-
impl_fn!(mod_data, ModData, defs);
6665
impl_fn!(typedef, TypeDefData, defs);
6766
impl_fn!(variable, VariableData, defs);
6867

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

7675
impl_fn!(macro_use, MacroUseData, macro_refs);
7776

77+
fn mod_data(&mut self, data: ModData) {
78+
let id: Id = From::from(data.id);
79+
let mut def = Def {
80+
kind: DefKind::Mod,
81+
id: id,
82+
span: data.span,
83+
name: data.name,
84+
qualname: data.qualname,
85+
value: data.filename,
86+
children: data.items.into_iter().map(|id| From::from(id)).collect(),
87+
decl_id: None,
88+
docs: data.docs,
89+
};
90+
if def.span.file_name != def.value {
91+
// If the module is an out-of-line defintion, then we'll make the
92+
// defintion the first character in the module's file and turn the
93+
// the declaration into a reference to it.
94+
let rf = Ref {
95+
kind: RefKind::Mod,
96+
span: def.span,
97+
ref_id: id,
98+
};
99+
self.result.refs.push(rf);
100+
def.span = SpanData {
101+
file_name: def.value.clone(),
102+
byte_start: 0,
103+
byte_end: 0,
104+
line_start: 1,
105+
line_end: 1,
106+
column_start: 1,
107+
column_end: 1,
108+
}
109+
}
110+
111+
self.result.defs.push(def);
112+
}
113+
78114
// FIXME store this instead of throwing it away.
79115
fn impl_data(&mut self, _data: ImplData) {}
80116
fn inheritance(&mut self, _data: InheritanceData) {}
@@ -111,7 +147,7 @@ impl Analysis {
111147

112148
// DefId::index is a newtype and so the JSON serialisation is ugly. Therefore
113149
// we use our own Id which is the same, but without the newtype.
114-
#[derive(Debug, RustcEncodable)]
150+
#[derive(Clone, Copy, Debug, RustcEncodable)]
115151
struct Id {
116152
krate: u32,
117153
index: u32,
@@ -337,21 +373,7 @@ impl From<MacroData> for Def {
337373
}
338374
}
339375
}
340-
impl From<ModData> for Def {
341-
fn from(data:ModData) -> Def {
342-
Def {
343-
kind: DefKind::Mod,
344-
id: From::from(data.id),
345-
span: data.span,
346-
name: data.name,
347-
qualname: data.qualname,
348-
value: data.filename,
349-
children: data.items.into_iter().map(|id| From::from(id)).collect(),
350-
decl_id: None,
351-
docs: data.docs,
352-
}
353-
}
354-
}
376+
355377
impl From<TypeDefData> for Def {
356378
fn from(data: TypeDefData) -> Def {
357379
Def {

0 commit comments

Comments
 (0)