Skip to content

Commit 5cd3396

Browse files
BoxyUwUcamelid
authored andcommitted
Fix const qualifs under mgca
1 parent 7ad324f commit 5cd3396

File tree

1 file changed

+11
-3
lines changed
  • compiler/rustc_const_eval/src/check_consts

1 file changed

+11
-3
lines changed

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
// having basically only two use-cases that act in different ways.
77

88
use rustc_errors::ErrorGuaranteed;
9-
use rustc_hir::LangItem;
9+
use rustc_hir::attrs::AttributeKind;
10+
use rustc_hir::def::DefKind;
11+
use rustc_hir::{LangItem, find_attr};
1012
use rustc_infer::infer::TyCtxtInferExt;
1113
use rustc_middle::mir::*;
1214
use rustc_middle::ty::{self, AdtDef, Ty};
@@ -365,8 +367,14 @@ where
365367
// check performed after the promotion. Verify that with an assertion.
366368
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
367369

368-
// Don't peek inside trait associated constants.
369-
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() {
370+
// Avoid looking at attrs of anon consts as that will ICE
371+
let is_type_const_item =
372+
matches!(cx.tcx.def_kind(def), DefKind::Const | DefKind::AssocConst)
373+
&& find_attr!(cx.tcx.get_all_attrs(def), AttributeKind::TypeConst(_));
374+
375+
// Don't peak inside trait associated consatnts, also `#[type_const] const` items
376+
// don't have bodies so there's nothing to look at
377+
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() && !is_type_const_item {
370378
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
371379

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

0 commit comments

Comments
 (0)