diff options
| author | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-01-09 17:31:16 +0100 |
|---|---|---|
| committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-01-09 19:59:54 +0100 |
| commit | c47ed149b2efe537822632c11d0675bdfb3d790c (patch) | |
| tree | 44c8717ee9cd99e4366d402acc4b3951d01de770 | |
| parent | 8c97b6ffbf0cec856c0b729c549141b5ac4b2d48 (diff) | |
| download | rust-c47ed149b2efe537822632c11d0675bdfb3d790c.tar.gz rust-c47ed149b2efe537822632c11d0675bdfb3d790c.zip | |
save-analysis: Get path def from parent in case there's no def for the path itself.
This fixes #57462.
The relevant part from the hir type collector is:
```
DEBUG 2019-01-09T15:42:58Z: rustc::hir::map::collector: hir_map: NodeId(32) => Entry { parent: NodeId(33), dep_node: 4294967040, node: Expr(expr(32: <Foo>::new)) }
DEBUG 2019-01-09T15:42:58Z: rustc::hir::map::collector: hir_map: NodeId(48) => Entry { parent: NodeId(32), dep_node: 4294967040, node: Ty(type(Foo)) }
DEBUG 2019-01-09T15:42:58Z: rustc::hir::map::collector: hir_map: NodeId(30) => Entry { parent: NodeId(48), dep_node: 4294967040, node: PathSegment(PathSegment { ident: Foo#0, id: Some(NodeId(30)), def: Some(Err), args: None, infer_types: true }) }
DEBUG 2019-01-09T15:42:58Z: rustc::hir::map::collector: hir_map: NodeId(31) => Entry { parent: NodeId(32), dep_node: 4294967040, node: PathSegment(PathSegment { ident: new#0, id: Some(NodeId(31)), def: Some(Err), args: None, infer_types: true }) }
```
We have the right ID when looking for NodeId(31) and try with NodeId(32) (which
is the right thing to look for) from get_path_data, but not for the segments
that we write from `write_sub_paths_truncated`.
Basically `process_path` takes an id which is always the parent, and that we
fall back to in `get_path_data()`, so we get the right result for the last path
segment, but not for the other segments that get written to from
`write_sub_paths_truncated`.
I think we can stop passing the explicit id around to `get_path_data` now, will
consider sending that as a followup.
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index d5b3070372b..00431f86cf5 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -622,9 +622,11 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { Node::Visibility(&Spanned { node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.def, - Node::PathSegment(seg) => match seg.def { - Some(def) => def, - None => HirDef::Err, + Node::PathSegment(seg) => { + match seg.def { + Some(def) if def != HirDef::Err => def, + _ => self.get_path_def(self.tcx.hir().get_parent_node(id)), + } }, Node::Expr(&hir::Expr { node: hir::ExprKind::Struct(ref qpath, ..), |
