From 1eef17e076b350ee68245948accb8a4264f19210 Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Tue, 19 Dec 2023 14:14:17 -0800 Subject: [PATCH] Fix crash for `CrateItem::kind()` with constructors Change how we classify item kind for DefKind::Ctor --- compiler/rustc_smir/src/rustc_smir/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index ae6cf3fe3e86d..06fcc9d40c96a 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -7,7 +7,7 @@ //! //! For now, we are developing everything inside `rustc`, thus, we keep this module private. -use rustc_hir::def::DefKind; +use rustc_hir::def::{CtorKind, DefKind}; use rustc_middle::mir; use rustc_middle::mir::interpret::AllocId; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; @@ -85,14 +85,17 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind { | DefKind::Field | DefKind::LifetimeParam | DefKind::Impl { .. } - | DefKind::Ctor(_, _) | DefKind::GlobalAsm => { unreachable!("Not a valid item kind: {kind:?}"); } - DefKind::Closure | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn, - DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => { - ItemKind::Const + DefKind::Ctor(_, CtorKind::Fn) | DefKind::Closure | DefKind::AssocFn | DefKind::Fn => { + ItemKind::Fn } + DefKind::Ctor(_, CtorKind::Const) + | DefKind::Const + | DefKind::InlineConst + | DefKind::AssocConst + | DefKind::AnonConst => ItemKind::Const, DefKind::Static(_) => ItemKind::Static, } }