Skip to content

Commit 4122d4a

Browse files
committed
Fix yet more ICEs
1 parent d322846 commit 4122d4a

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use rustc_errors::ErrorGuaranteed;
99
use rustc_hir::LangItem;
10+
use rustc_hir::def::DefKind;
1011
use rustc_infer::infer::TyCtxtInferExt;
1112
use rustc_middle::mir::*;
1213
use rustc_middle::ty::{self, AdtDef, Ty};
@@ -368,8 +369,12 @@ where
368369
// check performed after the promotion. Verify that with an assertion.
369370
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
370371

371-
// Don't peek inside trait associated constants.
372-
if promoted.is_none() && cx.tcx.trait_of_item(def).is_none() {
372+
// Const items don't themselves have bodies -- they will have either a path or an anon const instead.
373+
// FIXME(mgca): is this really the right behavior? should we return the qualifs of the anon const body instead?
374+
// (note also that original code ignored trait assoc items)
375+
if promoted.is_none()
376+
&& !matches!(cx.tcx.def_kind(def), DefKind::Const | DefKind::AssocConst)
377+
{
373378
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
374379

375380
if !Q::in_qualifs(&qualifs) {

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,6 +4280,7 @@ pub enum ItemKind<'hir> {
42804280
/// A `static` item.
42814281
Static(Ident, &'hir Ty<'hir>, Mutability, BodyId),
42824282
/// A `const` item.
4283+
// TODO: make sure we only allow usage of path RHS in generic contexts under mgca, not stable!
42834284
Const(Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, &'hir ConstArg<'hir>),
42844285
/// A function declaration.
42854286
Fn {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
13101310

13111311
fn should_encode_const(def_kind: DefKind) -> bool {
13121312
match def_kind {
1313+
// FIXME(mgca): should we remove Const and AssocConst here?
13131314
DefKind::Const | DefKind::AssocConst | DefKind::AnonConst | DefKind::InlineConst => true,
13141315

13151316
DefKind::Struct

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,9 @@ fn mir_promoted(
418418
{
419419
tcx.mir_const_qualif(def)
420420
}
421-
DefKind::AssocConst
422-
| DefKind::Const
423-
| DefKind::Static { .. }
424-
| DefKind::InlineConst
425-
| DefKind::AnonConst => tcx.mir_const_qualif(def),
421+
DefKind::Static { .. } | DefKind::InlineConst | DefKind::AnonConst => {
422+
tcx.mir_const_qualif(def)
423+
}
426424
_ => ConstQualifs::default(),
427425
};
428426

0 commit comments

Comments
 (0)