Skip to content

Commit 6cdcd5c

Browse files
authored
Rollup merge of rust-lang#50399 - nrc:alias, r=eddyb
save-analysis: handle aliasing imports a bit more nicely r? @eddyb
2 parents 0bfe307 + 7b378b2 commit 6cdcd5c

File tree

3 files changed

+20
-94
lines changed

3 files changed

+20
-94
lines changed

src/Cargo.lock

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

src/librustc_save_analysis/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rustc_target = { path = "../librustc_target" }
1616
rustc_typeck = { path = "../librustc_typeck" }
1717
syntax = { path = "../libsyntax" }
1818
syntax_pos = { path = "../libsyntax_pos" }
19-
rls-data = "0.15"
19+
rls-data = "0.16"
2020
rls-span = "0.4"
2121
# FIXME(#40527) should move rustc serialize out of tree
2222
rustc-serialize = "0.3"

src/librustc_save_analysis/dump_visitor.rs

+8-92
Original file line numberDiff line numberDiff line change
@@ -268,80 +268,6 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
268268
}
269269
}
270270

271-
fn process_def_kind(
272-
&mut self,
273-
ref_id: NodeId,
274-
span: Span,
275-
sub_span: Option<Span>,
276-
def_id: DefId,
277-
) {
278-
if self.span.filter_generated(sub_span, span) {
279-
return;
280-
}
281-
282-
let def = self.save_ctxt.get_path_def(ref_id);
283-
match def {
284-
HirDef::Mod(_) => {
285-
let span = self.span_from_span(sub_span.expect("No span found for mod ref"));
286-
self.dumper.dump_ref(Ref {
287-
kind: RefKind::Mod,
288-
span,
289-
ref_id: ::id_from_def_id(def_id),
290-
});
291-
}
292-
HirDef::Struct(..) |
293-
HirDef::Variant(..) |
294-
HirDef::Union(..) |
295-
HirDef::Enum(..) |
296-
HirDef::TyAlias(..) |
297-
HirDef::TyForeign(..) |
298-
HirDef::TraitAlias(..) |
299-
HirDef::Trait(_) => {
300-
let span = self.span_from_span(sub_span.expect("No span found for type ref"));
301-
self.dumper.dump_ref(Ref {
302-
kind: RefKind::Type,
303-
span,
304-
ref_id: ::id_from_def_id(def_id),
305-
});
306-
}
307-
HirDef::Static(..) |
308-
HirDef::Const(..) |
309-
HirDef::StructCtor(..) |
310-
HirDef::VariantCtor(..) => {
311-
let span = self.span_from_span(sub_span.expect("No span found for var ref"));
312-
self.dumper.dump_ref(Ref {
313-
kind: RefKind::Variable,
314-
span,
315-
ref_id: ::id_from_def_id(def_id),
316-
});
317-
}
318-
HirDef::Fn(..) => {
319-
let span = self.span_from_span(sub_span.expect("No span found for fn ref"));
320-
self.dumper.dump_ref(Ref {
321-
kind: RefKind::Function,
322-
span,
323-
ref_id: ::id_from_def_id(def_id),
324-
});
325-
}
326-
// With macros 2.0, we can legitimately get a ref to a macro, but
327-
// we don't handle it properly for now (FIXME).
328-
HirDef::Macro(..) => {}
329-
HirDef::Local(..) |
330-
HirDef::Upvar(..) |
331-
HirDef::SelfTy(..) |
332-
HirDef::Label(_) |
333-
HirDef::TyParam(..) |
334-
HirDef::Method(..) |
335-
HirDef::AssociatedTy(..) |
336-
HirDef::AssociatedConst(..) |
337-
HirDef::PrimTy(_) |
338-
HirDef::GlobalAsm(_) |
339-
HirDef::Err => {
340-
span_bug!(span, "process_def_kind for unexpected item: {:?}", def);
341-
}
342-
}
343-
}
344-
345271
fn process_formals(&mut self, formals: &'l [ast::Arg], qualname: &str) {
346272
for arg in formals {
347273
self.visit_pat(&arg.pat);
@@ -1348,29 +1274,17 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
13481274
};
13491275

13501276
let sub_span = self.span.span_for_last_ident(path.span);
1351-
let mod_id = match self.lookup_def_id(id) {
1352-
Some(def_id) => {
1353-
self.process_def_kind(id, path.span, sub_span, def_id);
1354-
Some(def_id)
1355-
}
1356-
None => None,
1357-
};
1358-
1359-
// 'use' always introduces an alias, if there is not an explicit
1360-
// one, there is an implicit one.
1361-
let sub_span = match self.span.sub_span_after_keyword(use_tree.span,
1362-
keywords::As) {
1363-
Some(sub_span) => Some(sub_span),
1364-
None => sub_span,
1365-
};
1277+
let alias_span = self.span.sub_span_after_keyword(use_tree.span, keywords::As);
1278+
let ref_id = self.lookup_def_id(id);
13661279

13671280
if !self.span.filter_generated(sub_span, path.span) {
1368-
let span =
1369-
self.span_from_span(sub_span.expect("No span found for use"));
1281+
let span = self.span_from_span(sub_span.expect("No span found for use"));
1282+
let alias_span = alias_span.map(|sp| self.span_from_span(sp));
13701283
self.dumper.import(&access, Import {
13711284
kind: ImportKind::Use,
1372-
ref_id: mod_id.map(|id| ::id_from_def_id(id)),
1285+
ref_id: ref_id.map(|id| ::id_from_def_id(id)),
13731286
span,
1287+
alias_span,
13741288
name: ident.to_string(),
13751289
value: String::new(),
13761290
parent,
@@ -1407,6 +1321,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
14071321
kind: ImportKind::GlobUse,
14081322
ref_id: None,
14091323
span,
1324+
alias_span: None,
14101325
name: "*".to_owned(),
14111326
value: names.join(", "),
14121327
parent,
@@ -1500,6 +1415,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
15001415
kind: ImportKind::ExternCrate,
15011416
ref_id: None,
15021417
span,
1418+
alias_span: None,
15031419
name: item.ident.to_string(),
15041420
value: String::new(),
15051421
parent,

0 commit comments

Comments
 (0)