Skip to content

Commit 20c64e8

Browse files
committed
save-analysis: corrects reference for tuple struct and unit struct literals
Fixes rust-dev-tools/rls-analysis#77
1 parent 82a8968 commit 20c64e8

File tree

1 file changed

+13
-2
lines changed
  • src/librustc_save_analysis

1 file changed

+13
-2
lines changed

src/librustc_save_analysis/lib.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
579579
Node::NodeItem(&hir::Item { node: hir::ItemUse(ref path, _), .. }) |
580580
Node::NodeVisibility(&hir::Visibility::Restricted { ref path, .. }) => path.def,
581581

582-
Node::NodeExpr(&hir::Expr { node: hir::ExprPath(ref qpath), .. }) |
583582
Node::NodeExpr(&hir::Expr { node: hir::ExprStruct(ref qpath, ..), .. }) |
583+
Node::NodeExpr(&hir::Expr { node: hir::ExprPath(ref qpath), .. }) |
584584
Node::NodePat(&hir::Pat { node: hir::PatKind::Path(ref qpath), .. }) |
585585
Node::NodePat(&hir::Pat { node: hir::PatKind::Struct(ref qpath, ..), .. }) |
586586
Node::NodePat(&hir::Pat { node: hir::PatKind::TupleStruct(ref qpath, ..), .. }) => {
@@ -643,7 +643,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
643643
HirDef::Static(..) |
644644
HirDef::Const(..) |
645645
HirDef::AssociatedConst(..) |
646-
HirDef::StructCtor(..) |
647646
HirDef::VariantCtor(..) => {
648647
let span = self.span_from_span(sub_span.unwrap());
649648
Some(Ref {
@@ -678,6 +677,18 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
678677
ref_id: id_from_def_id(def_id),
679678
})
680679
}
680+
HirDef::StructCtor(def_id, _) => {
681+
// This is a reference to a tuple struct where the def_id points
682+
// to an invisible constructor function. That is not a very useful
683+
// def, so adjust to point to the tuple struct itself.
684+
let span = self.span_from_span(sub_span.unwrap());
685+
let parent_def_id = self.tcx.parent_def_id(def_id).unwrap();
686+
Some(Ref {
687+
kind: RefKind::Type,
688+
span,
689+
ref_id: id_from_def_id(parent_def_id),
690+
})
691+
}
681692
HirDef::Method(decl_id) => {
682693
let sub_span = self.span_utils.sub_span_for_meth_name(path.span);
683694
filter!(self.span_utils, sub_span, path.span, None);

0 commit comments

Comments
 (0)