Skip to content

Commit 8b55768

Browse files
committed
Fix const qualifs under mgca
1 parent 1038dad commit 8b55768

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};
@@ -366,8 +368,14 @@ where
366368
// check performed after the promotion. Verify that with an assertion.
367369
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
368370

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

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

0 commit comments

Comments
 (0)