@@ -19,7 +19,7 @@ use rustc_middle::mir::{self, Rvalue, StatementKind, TerminatorKind};
1919use rustc_middle:: ty:: subst:: { Subst , SubstsRef } ;
2020use rustc_middle:: ty:: { self , TyCtxt , TypeFoldable } ;
2121use rustc_session:: lint;
22- use rustc_span:: def_id:: { DefId , LocalDefId } ;
22+ use rustc_span:: def_id:: LocalDefId ;
2323use rustc_span:: Span ;
2424
2525use std:: cmp;
@@ -29,26 +29,20 @@ use std::ops::ControlFlow;
2929/// Check if a given constant can be evaluated.
3030pub fn is_const_evaluatable < ' cx , ' tcx > (
3131 infcx : & InferCtxt < ' cx , ' tcx > ,
32- def : ty:: WithOptConstParam < DefId > ,
33- substs : SubstsRef < ' tcx > ,
32+ uv : ty:: Unevaluated < ' tcx > ,
3433 param_env : ty:: ParamEnv < ' tcx > ,
3534 span : Span ,
3635) -> Result < ( ) , NotConstEvaluatable > {
37- debug ! ( "is_const_evaluatable({:?}, {:?} )" , def , substs ) ;
36+ debug ! ( "is_const_evaluatable({:?})" , uv ) ;
3837 if infcx. tcx . features ( ) . const_evaluatable_checked {
3938 let tcx = infcx. tcx ;
40- match AbstractConst :: new ( tcx, def , substs ) ? {
39+ match AbstractConst :: new ( tcx, uv ) ? {
4140 // We are looking at a generic abstract constant.
4241 Some ( ct) => {
4342 for pred in param_env. caller_bounds ( ) {
4443 match pred. kind ( ) . skip_binder ( ) {
45- ty:: PredicateKind :: ConstEvaluatable ( b_def, b_substs) => {
46- if b_def == def && b_substs == substs {
47- debug ! ( "is_const_evaluatable: caller_bound ~~> ok" ) ;
48- return Ok ( ( ) ) ;
49- }
50-
51- if let Some ( b_ct) = AbstractConst :: new ( tcx, b_def, b_substs) ? {
44+ ty:: PredicateKind :: ConstEvaluatable ( uv) => {
45+ if let Some ( b_ct) = AbstractConst :: new ( tcx, uv) ? {
5246 // Try to unify with each subtree in the AbstractConst to allow for
5347 // `N + 1` being const evaluatable even if theres only a `ConstEvaluatable`
5448 // predicate for `(N + 1) * 2`
@@ -134,7 +128,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
134128 }
135129
136130 let future_compat_lint = || {
137- if let Some ( local_def_id) = def. did . as_local ( ) {
131+ if let Some ( local_def_id) = uv . def . did . as_local ( ) {
138132 infcx. tcx . struct_span_lint_hir (
139133 lint:: builtin:: CONST_EVALUATABLE_UNCHECKED ,
140134 infcx. tcx . hir ( ) . local_def_id_to_hir_id ( local_def_id) ,
@@ -155,13 +149,12 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
155149 // and hopefully soon change this to an error.
156150 //
157151 // See #74595 for more details about this.
158- let concrete =
159- infcx. const_eval_resolve ( param_env, ty:: Unevaluated :: new ( def, substs) , Some ( span) ) ;
152+ let concrete = infcx. const_eval_resolve ( param_env, uv, Some ( span) ) ;
160153
161- if concrete. is_ok ( ) && substs. has_param_types_or_consts ( infcx. tcx ) {
162- match infcx. tcx . def_kind ( def. did ) {
154+ if concrete. is_ok ( ) && uv . substs ( infcx . tcx ) . has_param_types_or_consts ( infcx. tcx ) {
155+ match infcx. tcx . def_kind ( uv . def . did ) {
163156 DefKind :: AnonConst => {
164- let mir_body = infcx. tcx . mir_for_ctfe_opt_const_arg ( def) ;
157+ let mir_body = infcx. tcx . mir_for_ctfe_opt_const_arg ( uv . def ) ;
165158
166159 if mir_body. is_polymorphic {
167160 future_compat_lint ( ) ;
@@ -173,7 +166,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
173166
174167 debug ! ( ?concrete, "is_const_evaluatable" ) ;
175168 match concrete {
176- Err ( ErrorHandled :: TooGeneric ) => Err ( match substs . has_infer_types_or_consts ( ) {
169+ Err ( ErrorHandled :: TooGeneric ) => Err ( match uv . has_infer_types_or_consts ( ) {
177170 true => NotConstEvaluatable :: MentionsInfer ,
178171 false => NotConstEvaluatable :: MentionsParam ,
179172 } ) ,
@@ -198,23 +191,22 @@ pub struct AbstractConst<'tcx> {
198191 pub substs : SubstsRef < ' tcx > ,
199192}
200193
201- impl AbstractConst < ' tcx > {
194+ impl < ' tcx > AbstractConst < ' tcx > {
202195 pub fn new (
203196 tcx : TyCtxt < ' tcx > ,
204- def : ty:: WithOptConstParam < DefId > ,
205- substs : SubstsRef < ' tcx > ,
197+ uv : ty:: Unevaluated < ' tcx > ,
206198 ) -> Result < Option < AbstractConst < ' tcx > > , ErrorReported > {
207- let inner = tcx. mir_abstract_const_opt_const_arg ( def) ?;
208- debug ! ( "AbstractConst::new({:?}) = {:?}" , def , inner) ;
209- Ok ( inner. map ( |inner| AbstractConst { inner, substs } ) )
199+ let inner = tcx. mir_abstract_const_opt_const_arg ( uv . def ) ?;
200+ debug ! ( "AbstractConst::new({:?}) = {:?}" , uv , inner) ;
201+ Ok ( inner. map ( |inner| AbstractConst { inner, substs : uv . substs ( tcx ) } ) )
210202 }
211203
212204 pub fn from_const (
213205 tcx : TyCtxt < ' tcx > ,
214206 ct : & ty:: Const < ' tcx > ,
215207 ) -> Result < Option < AbstractConst < ' tcx > > , ErrorReported > {
216208 match ct. val {
217- ty:: ConstKind :: Unevaluated ( uv) => AbstractConst :: new ( tcx, uv. def , uv . substs ( tcx ) ) ,
209+ ty:: ConstKind :: Unevaluated ( uv) => AbstractConst :: new ( tcx, uv) ,
218210 ty:: ConstKind :: Error ( _) => Err ( ErrorReported ) ,
219211 _ => Ok ( None ) ,
220212 }
@@ -564,14 +556,11 @@ pub(super) fn mir_abstract_const<'tcx>(
564556
565557pub ( super ) fn try_unify_abstract_consts < ' tcx > (
566558 tcx : TyCtxt < ' tcx > ,
567- ( ( a, a_substs) , ( b, b_substs) ) : (
568- ( ty:: WithOptConstParam < DefId > , SubstsRef < ' tcx > ) ,
569- ( ty:: WithOptConstParam < DefId > , SubstsRef < ' tcx > ) ,
570- ) ,
559+ ( a, b) : ( ty:: Unevaluated < ' tcx > , ty:: Unevaluated < ' tcx > ) ,
571560) -> bool {
572561 ( || {
573- if let Some ( a) = AbstractConst :: new ( tcx, a, a_substs ) ? {
574- if let Some ( b) = AbstractConst :: new ( tcx, b, b_substs ) ? {
562+ if let Some ( a) = AbstractConst :: new ( tcx, a) ? {
563+ if let Some ( b) = AbstractConst :: new ( tcx, b) ? {
575564 return Ok ( try_unify ( tcx, a, b) ) ;
576565 }
577566 }
0 commit comments