diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2017-11-02 11:28:13 +1300 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2017-11-02 11:28:56 +1300 |
| commit | 20c64e8155b0c29e8cbb4b9a8c99fd0a94a3caa2 (patch) | |
| tree | 7e82a3ec2ea8b72f9c015cbfb126e5e204b83f24 | |
| parent | 82a8968ce09f1fd15291f2b3e51a89178a6d0674 (diff) | |
| download | rust-20c64e8155b0c29e8cbb4b9a8c99fd0a94a3caa2.tar.gz rust-20c64e8155b0c29e8cbb4b9a8c99fd0a94a3caa2.zip | |
save-analysis: corrects reference for tuple struct and unit struct literals
Fixes https://github.com/nrc/rls-analysis/issues/77
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 9769f3905c7..63dde756787 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -579,8 +579,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { Node::NodeItem(&hir::Item { node: hir::ItemUse(ref path, _), .. }) | Node::NodeVisibility(&hir::Visibility::Restricted { ref path, .. }) => path.def, - Node::NodeExpr(&hir::Expr { node: hir::ExprPath(ref qpath), .. }) | Node::NodeExpr(&hir::Expr { node: hir::ExprStruct(ref qpath, ..), .. }) | + Node::NodeExpr(&hir::Expr { node: hir::ExprPath(ref qpath), .. }) | Node::NodePat(&hir::Pat { node: hir::PatKind::Path(ref qpath), .. }) | Node::NodePat(&hir::Pat { node: hir::PatKind::Struct(ref qpath, ..), .. }) | Node::NodePat(&hir::Pat { node: hir::PatKind::TupleStruct(ref qpath, ..), .. }) => { @@ -643,7 +643,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { HirDef::Static(..) | HirDef::Const(..) | HirDef::AssociatedConst(..) | - HirDef::StructCtor(..) | HirDef::VariantCtor(..) => { let span = self.span_from_span(sub_span.unwrap()); Some(Ref { @@ -678,6 +677,18 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { ref_id: id_from_def_id(def_id), }) } + HirDef::StructCtor(def_id, _) => { + // This is a reference to a tuple struct where the def_id points + // to an invisible constructor function. That is not a very useful + // def, so adjust to point to the tuple struct itself. + let span = self.span_from_span(sub_span.unwrap()); + let parent_def_id = self.tcx.parent_def_id(def_id).unwrap(); + Some(Ref { + kind: RefKind::Type, + span, + ref_id: id_from_def_id(parent_def_id), + }) + } HirDef::Method(decl_id) => { let sub_span = self.span_utils.sub_span_for_meth_name(path.span); filter!(self.span_utils, sub_span, path.span, None); |
