Skip to content

Commit e3afba5

Browse files
committed
Emit crate disambiguators in save-analysis data
1 parent f7b080b commit e3afba5

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/librustc_save_analysis/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
1515
rustc_typeck = { path = "../librustc_typeck" }
1616
syntax = { path = "../libsyntax" }
1717
syntax_pos = { path = "../libsyntax_pos" }
18-
rls-data = "0.11"
18+
rls-data = { git = "https://github.com/Xanewok/rls-data", branch = "crate-source" }
1919
rls-span = "0.4"
2020
# FIXME(#40527) should move rustc serialize out of tree
2121
rustc-serialize = "0.3"

src/librustc_save_analysis/dump_visitor.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ use json_dumper::{JsonDumper, DumpOutput};
4646
use span_utils::SpanUtils;
4747
use sig;
4848

49-
use rls_data::{CratePreludeData, Import, ImportKind, SpanData, Ref, RefKind,
50-
Def, DefKind, Relation, RelationKind};
49+
use rls_data::{CratePreludeData, GlobalCrateId, Import, ImportKind, SpanData,
50+
Ref, RefKind, Def, DefKind, Relation, RelationKind};
5151

5252
macro_rules! down_cast_data {
5353
($id:ident, $kind:ident, $sp:expr) => {
@@ -131,7 +131,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
131131
});
132132

133133
let data = CratePreludeData {
134-
crate_name: name.into(),
134+
crate_id: GlobalCrateId {
135+
name: name.into(),
136+
disambiguator: self.tcx.sess.local_crate_disambiguator().to_string(),
137+
},
135138
crate_root: crate_root.unwrap_or("<no source>".to_owned()),
136139
external_crates: self.save_ctxt.get_external_crates(),
137140
span: self.span_from_span(krate.span),

src/librustc_save_analysis/lib.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use dump_visitor::DumpVisitor;
6363
use span_utils::SpanUtils;
6464

6565
use rls_data::{Ref, RefKind, SpanData, MacroRef, Def, DefKind, Relation, RelationKind,
66-
ExternalCrateData};
66+
ExternalCrateData, GlobalCrateId};
6767
use rls_data::config::Config;
6868

6969

@@ -82,10 +82,6 @@ pub enum Data {
8282
RelationData(Relation),
8383
}
8484

85-
macro_rules! option_try(
86-
($e:expr) => (match $e { Some(e) => e, None => return None })
87-
);
88-
8985
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
9086
fn span_from_span(&self, span: Span) -> SpanData {
9187
use rls_span::{Row, Column};
@@ -119,9 +115,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
119115
};
120116
let lo_loc = self.span_utils.sess.codemap().lookup_char_pos(span.lo());
121117
result.push(ExternalCrateData {
122-
name: self.tcx.crate_name(n).to_string(),
123-
num: n.as_u32(),
124118
file_name: SpanUtils::make_path_string(&lo_loc.file.name),
119+
num: n.as_u32(),
120+
id: GlobalCrateId {
121+
name: self.tcx.crate_name(n).to_string(),
122+
disambiguator: self.tcx.crate_disambiguator(n).to_string(),
123+
},
125124
});
126125
}
127126

@@ -725,8 +724,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
725724
// macro uses.
726725
let callsite = span.source_callsite();
727726
let callsite_span = self.span_from_span(callsite);
728-
let callee = option_try!(span.source_callee());
729-
let callee_span = option_try!(callee.span);
727+
let callee = span.source_callee()?;
728+
let callee_span = callee.span?;
730729

731730
// Ignore attribute macros, their spans are usually mangled
732731
if let MacroAttribute(_) = callee.format {

0 commit comments

Comments
 (0)