Skip to content

Commit

Permalink
Fix crash for CrateItem::kind() with constructors
Browse files Browse the repository at this point in the history
Change how we classify item kind for DefKind::Ctor
  • Loading branch information
celinval committed Dec 19, 2023
1 parent 36bb79f commit 1eef17e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 1eef17e

Please sign in to comment.