Skip to content

Commit 2379faa

Browse files
committed
Auto merge of #45468 - Xanewok:crate-source, r=nrc
Emit crate disambiguators in save-analysis data Needed for rust-dev-tools/rls-analysis#93. Blocked by rust-dev-tools/rls-data#11. (For now, this pulls my branch [rls-data/crate-source](https://github.com/Xanewok/rls-data/tree/crate-source)) This will allow to disambiguate different crates types/versions when indexing resulting save-analysis data (most importantly allow to support bin+lib and different crate versions). r? @nrc
2 parents d5b69d4 + b4ffede commit 2379faa

File tree

6 files changed

+36
-43
lines changed

6 files changed

+36
-43
lines changed

src/Cargo.lock

+13-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/ich/fingerprint.rs

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ impl Fingerprint {
2929
self.0
3030
}
3131

32+
#[inline]
33+
pub fn as_value(&self) -> (u64, u64) {
34+
(self.0, self.1)
35+
}
36+
3237
#[inline]
3338
pub fn combine(self, other: Fingerprint) -> Fingerprint {
3439
// See https://stackoverflow.com/a/27952689 on why this function is

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 = "0.12"
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

+7-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,11 @@ 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()
137+
.to_fingerprint().as_value(),
138+
},
135139
crate_root: crate_root.unwrap_or("<no source>".to_owned()),
136140
external_crates: self.save_ctxt.get_external_crates(),
137141
span: self.span_from_span(krate.span),

src/librustc_save_analysis/lib.rs

+9-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,13 @@ 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)
123+
.to_fingerprint().as_value(),
124+
},
125125
});
126126
}
127127

@@ -728,8 +728,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
728728
// macro uses.
729729
let callsite = span.source_callsite();
730730
let callsite_span = self.span_from_span(callsite);
731-
let callee = option_try!(span.source_callee());
732-
let callee_span = option_try!(callee.span);
731+
let callee = span.source_callee()?;
732+
let callee_span = callee.span?;
733733

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

src/tools/rls

Submodule rls updated from e034859 to 48fd42f

0 commit comments

Comments
 (0)