|
6 | 6 | // having basically only two use-cases that act in different ways. |
7 | 7 |
|
8 | 8 | 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}; |
10 | 12 | use rustc_infer::infer::TyCtxtInferExt; |
11 | 13 | use rustc_middle::mir::*; |
12 | 14 | use rustc_middle::ty::{self, AdtDef, Ty}; |
@@ -366,8 +368,14 @@ where |
366 | 368 | // check performed after the promotion. Verify that with an assertion. |
367 | 369 | assert!(promoted.is_none() || Q::ALLOW_PROMOTED); |
368 | 370 |
|
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 { |
371 | 379 | let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def); |
372 | 380 |
|
373 | 381 | if !Q::in_qualifs(&qualifs) { |
|
0 commit comments