Skip to content

Commit 4895dea

Browse files
committed
save-analysis: make sure we save the def for the last segment of a path
1 parent f586ac9 commit 4895dea

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/librustc/hir/lowering.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,6 @@ impl<'a> LoweringContext<'a> {
17541754
&mut self,
17551755
def: Def,
17561756
p: &Path,
1757-
ident: Option<Ident>,
17581757
param_mode: ParamMode,
17591758
explicit_owner: Option<NodeId>,
17601759
) -> hir::Path {
@@ -1773,15 +1772,14 @@ impl<'a> LoweringContext<'a> {
17731772
explicit_owner,
17741773
)
17751774
})
1776-
.chain(ident.map(|ident| hir::PathSegment::from_ident(ident)))
17771775
.collect(),
17781776
span: p.span,
17791777
}
17801778
}
17811779

17821780
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path {
17831781
let def = self.expect_full_def(id);
1784-
self.lower_path_extra(def, p, None, param_mode, None)
1782+
self.lower_path_extra(def, p, param_mode, None)
17851783
}
17861784

17871785
fn lower_path_segment(
@@ -3014,7 +3012,7 @@ impl<'a> LoweringContext<'a> {
30143012
self.with_hir_id_owner(new_node_id, |this| {
30153013
let new_id = this.lower_node_id(new_node_id);
30163014
let path =
3017-
this.lower_path_extra(def, &path, None, ParamMode::Explicit, None);
3015+
this.lower_path_extra(def, &path, ParamMode::Explicit, None);
30183016
let item = hir::ItemKind::Use(P(path), hir::UseKind::Single);
30193017
let vis_kind = match vis.node {
30203018
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
@@ -3053,7 +3051,7 @@ impl<'a> LoweringContext<'a> {
30533051
}
30543052

30553053
let path =
3056-
P(self.lower_path_extra(ret_def, &path, None, ParamMode::Explicit, None));
3054+
P(self.lower_path_extra(ret_def, &path, ParamMode::Explicit, None));
30573055
hir::ItemKind::Use(path, hir::UseKind::Single)
30583056
}
30593057
UseTreeKind::Glob => {
@@ -3140,7 +3138,7 @@ impl<'a> LoweringContext<'a> {
31403138
// the stability of `use a::{};`, to avoid it showing up as
31413139
// a re-export by accident when `pub`, e.g. in documentation.
31423140
let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err);
3143-
let path = P(self.lower_path_extra(def, &prefix, None, ParamMode::Explicit, None));
3141+
let path = P(self.lower_path_extra(def, &prefix, ParamMode::Explicit, None));
31443142
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited);
31453143
hir::ItemKind::Use(path, hir::UseKind::ListStem)
31463144
}
@@ -4550,7 +4548,6 @@ impl<'a> LoweringContext<'a> {
45504548
path: P(self.lower_path_extra(
45514549
def,
45524550
path,
4553-
None,
45544551
ParamMode::Explicit,
45554552
explicit_owner,
45564553
)),

src/librustc_resolve/lib.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -3589,7 +3589,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
35893589
);
35903590

35913591
for (i, &Segment { ident, id }) in path.iter().enumerate() {
3592-
debug!("resolve_path ident {} {:?}", i, ident);
3592+
debug!("resolve_path ident {} {:?} {:?}", i, ident, id);
3593+
let record_segment_def = |this: &mut Self, def| {
3594+
if record_used {
3595+
if let Some(id) = id {
3596+
if !this.def_map.contains_key(&id) {
3597+
assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
3598+
this.record_def(id, PathResolution::new(def));
3599+
}
3600+
}
3601+
}
3602+
};
35933603

35943604
let is_last = i == path.len() - 1;
35953605
let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
@@ -3673,6 +3683,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
36733683
// we found a local variable or type param
36743684
Some(LexicalScopeBinding::Def(def))
36753685
if opt_ns == Some(TypeNS) || opt_ns == Some(ValueNS) => {
3686+
record_segment_def(self, def);
36763687
return PathResult::NonModule(PathResolution::with_unresolved_segments(
36773688
def, path.len() - 1
36783689
));
@@ -3690,14 +3701,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
36903701
let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(def);
36913702
if let Some(next_module) = binding.module() {
36923703
module = Some(ModuleOrUniformRoot::Module(next_module));
3693-
if record_used {
3694-
if let Some(id) = id {
3695-
if !self.def_map.contains_key(&id) {
3696-
assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
3697-
self.record_def(id, PathResolution::new(def));
3698-
}
3699-
}
3700-
}
3704+
record_segment_def(self, def);
37013705
} else if def == Def::ToolMod && i + 1 != path.len() {
37023706
let def = Def::NonMacroAttr(NonMacroAttrKind::Tool);
37033707
return PathResult::NonModule(PathResolution::new(def));

src/librustc_save_analysis/dump_visitor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
771771
}
772772

773773
fn process_path(&mut self, id: NodeId, path: &'l ast::Path) {
774-
debug!("process_path {:?}", path);
775-
if generated_code(path.span) {
774+
if self.span.filter_generated(path.span) {
776775
return;
777776
}
778777
self.dump_path_ref(id, path);

0 commit comments

Comments
 (0)