Skip to content

Commit 5bfa7f0

Browse files
committed
save_analysis: fix enum reference to point to variant rather than constructor
Fixes #61302
1 parent 9015c41 commit 5bfa7f0

File tree

1 file changed

+7
-11
lines changed
  • src/librustc_save_analysis

1 file changed

+7
-11
lines changed

src/librustc_save_analysis/lib.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::ast::{self};
1313
use rustc_ast::util::comments::strip_doc_comment_decoration;
1414
use rustc_ast_pretty::pprust::attribute_to_string;
1515
use rustc_hir as hir;
16-
use rustc_hir::def::{CtorOf, DefKind as HirDefKind, Res};
16+
use rustc_hir::def::{DefKind as HirDefKind, Res};
1717
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1818
use rustc_hir::intravisit::{self, Visitor};
1919
use rustc_hir::Node;
@@ -708,20 +708,16 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
708708
Res::Def(HirDefKind::ConstParam, def_id) => {
709709
Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(def_id) })
710710
}
711-
Res::Def(HirDefKind::Ctor(CtorOf::Struct, ..), def_id) => {
712-
// This is a reference to a tuple struct where the def_id points
711+
Res::Def(HirDefKind::Ctor(_, ..), def_id) => {
712+
// This is a reference to a tuple struct or an enum variant where the def_id points
713713
// to an invisible constructor function. That is not a very useful
714-
// def, so adjust to point to the tuple struct itself.
714+
// def, so adjust to point to the tuple struct or enum variant itself.
715715
let parent_def_id = self.tcx.parent(def_id).unwrap();
716716
Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(parent_def_id) })
717717
}
718-
Res::Def(
719-
HirDefKind::Static
720-
| HirDefKind::Const
721-
| HirDefKind::AssocConst
722-
| HirDefKind::Ctor(..),
723-
_,
724-
) => Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(res.def_id()) }),
718+
Res::Def(HirDefKind::Static | HirDefKind::Const | HirDefKind::AssocConst, _) => {
719+
Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(res.def_id()) })
720+
}
725721
Res::Def(HirDefKind::AssocFn, decl_id) => {
726722
let def_id = if decl_id.is_local() {
727723
let ti = self.tcx.associated_item(decl_id);

0 commit comments

Comments
 (0)