File tree Expand file tree Collapse file tree 2 files changed +33
-9
lines changed
compiler/rustc_middle/src/mir/interpret Expand file tree Collapse file tree 2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -115,15 +115,16 @@ impl<'tcx> TyCtxt<'tcx> {
115115 // @lcnr believes that successfully evaluating even though there are
116116 // used generic parameters is a bug of evaluation, so checking for it
117117 // here does feel somewhat sensible.
118- if !self . features ( ) . generic_const_exprs ( ) && ct. args . has_non_region_param ( ) {
119- let def_kind = self . def_kind ( instance. def_id ( ) ) ;
120- assert ! (
121- matches!(
122- def_kind,
123- DefKind :: InlineConst | DefKind :: AnonConst | DefKind :: AssocConst
124- ) ,
125- "{cid:?} is {def_kind:?}" ,
126- ) ;
118+ if !self . features ( ) . generic_const_exprs ( )
119+ && ct. args . has_non_region_param ( )
120+ // We only FCW for anon consts as repeat expr counts with anon consts are the only place
121+ // that we have a back compat hack for. We don't need to check this is a const argument
122+ // as only anon consts as const args should get evaluated "for the type system".
123+ //
124+ // If we don't *only* FCW anon consts we can wind up incorrectly FCW'ing uses of assoc
125+ // consts in pattern positions. #140447
126+ && self . def_kind ( instance. def_id ( ) ) == DefKind :: AnonConst
127+ {
127128 let mir_body = self . mir_for_ctfe ( instance. def_id ( ) ) ;
128129 if mir_body. is_polymorphic {
129130 let Some ( local_def_id) = ct. def . as_local ( ) else { return } ;
Original file line number Diff line number Diff line change 1+ //@ check-pass
2+
3+ // Previously the `CONST_EVALUATABLE_UNCHECKED` FCW would fire on const evaluation of
4+ // associated consts. This is unnecessary as the FCW only needs to apply for repeat expr
5+ // counts which are anon consts with generic parameters provided. #140447
6+
7+ pub struct Foo < const N : usize > ;
8+
9+ impl < const N : usize > Foo < N > {
10+ const UNUSED_PARAM : usize = {
11+ let _: [ ( ) ; N ] ;
12+ 3
13+ } ;
14+
15+ pub fn bar ( ) {
16+ match 1 {
17+ Self :: UNUSED_PARAM => ( ) ,
18+ _ => ( ) ,
19+ }
20+ }
21+ }
22+
23+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments