@@ -578,16 +578,28 @@ pub fn try_evaluate_const<'tcx>(
578
578
( args, param_env)
579
579
}
580
580
}
581
- } else {
582
- // FIXME: We don't check anything on stable as the only way we can wind up with
583
- // an unevaluated constant containing generic parameters is through array repeat
584
- // expression counts which have a future compat lint for usage of generic parameters
585
- // instead of a hard error.
581
+ } else if tcx. def_kind ( uv. def ) == DefKind :: AnonConst && uv. has_non_region_infer ( ) {
582
+ // FIXME: remove this when `const_evaluatable_unchecked` is a hard error.
583
+ //
584
+ // Diagnostics will sometimes replace the identity args of anon consts in
585
+ // array repeat expr counts with inference variables so we have to handle this
586
+ // even though it is not something we should ever actually encounter.
586
587
//
587
- // This codepath is however also reachable by `generic_const_exprs` and some other
588
- // feature gates which allow constants in the type system to use generic parameters.
589
- // In theory we should be checking for generic parameters here and returning an error
590
- // in such cases.
588
+ // Array repeat expr counts are allowed to syntactically use generic parameters
589
+ // but must not actually depend on them in order to evalaute succesfully. This means
590
+ // that it is actually fine to evalaute them in their own environment rather than with
591
+ // the actually provided generic arguments.
592
+ tcx. dcx ( ) . delayed_bug (
593
+ "Encountered anon const with inference variable args but no error reported" ,
594
+ ) ;
595
+
596
+ let args = GenericArgs :: identity_for_item ( tcx, uv. def ) ;
597
+ let param_env = tcx. param_env ( uv. def ) ;
598
+ ( args, param_env)
599
+ } else {
600
+ // FIXME: This codepath is reachable under `associated_const_equality` and in the
601
+ // future will be reachable by `min_generic_const_args`. We should handle inference
602
+ // variables and generic parameters properly instead of doing nothing.
591
603
( uv. args , param_env)
592
604
} ;
593
605
let uv = ty:: UnevaluatedConst :: new ( uv. def , args) ;
0 commit comments