@@ -19,7 +19,7 @@ use rustc_middle::mir::{self, Rvalue, StatementKind, TerminatorKind};
19
19
use rustc_middle:: ty:: subst:: { Subst , SubstsRef } ;
20
20
use rustc_middle:: ty:: { self , TyCtxt , TypeFoldable } ;
21
21
use rustc_session:: lint;
22
- use rustc_span:: def_id:: { DefId , LocalDefId } ;
22
+ use rustc_span:: def_id:: LocalDefId ;
23
23
use rustc_span:: Span ;
24
24
25
25
use std:: cmp;
@@ -29,26 +29,20 @@ use std::ops::ControlFlow;
29
29
/// Check if a given constant can be evaluated.
30
30
pub fn is_const_evaluatable < ' cx , ' tcx > (
31
31
infcx : & InferCtxt < ' cx , ' tcx > ,
32
- def : ty:: WithOptConstParam < DefId > ,
33
- substs : SubstsRef < ' tcx > ,
32
+ uv : ty:: Unevaluated < ' tcx > ,
34
33
param_env : ty:: ParamEnv < ' tcx > ,
35
34
span : Span ,
36
35
) -> Result < ( ) , NotConstEvaluatable > {
37
- debug ! ( "is_const_evaluatable({:?}, {:?} )" , def , substs ) ;
36
+ debug ! ( "is_const_evaluatable({:?})" , uv ) ;
38
37
if infcx. tcx . features ( ) . const_evaluatable_checked {
39
38
let tcx = infcx. tcx ;
40
- match AbstractConst :: new ( tcx, def , substs ) ? {
39
+ match AbstractConst :: new ( tcx, uv ) ? {
41
40
// We are looking at a generic abstract constant.
42
41
Some ( ct) => {
43
42
for pred in param_env. caller_bounds ( ) {
44
43
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) ? {
52
46
// Try to unify with each subtree in the AbstractConst to allow for
53
47
// `N + 1` being const evaluatable even if theres only a `ConstEvaluatable`
54
48
// predicate for `(N + 1) * 2`
@@ -134,7 +128,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
134
128
}
135
129
136
130
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 ( ) {
138
132
infcx. tcx . struct_span_lint_hir (
139
133
lint:: builtin:: CONST_EVALUATABLE_UNCHECKED ,
140
134
infcx. tcx . hir ( ) . local_def_id_to_hir_id ( local_def_id) ,
@@ -155,13 +149,12 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
155
149
// and hopefully soon change this to an error.
156
150
//
157
151
// 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) ) ;
160
153
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 ) {
163
156
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 ) ;
165
158
166
159
if mir_body. is_polymorphic {
167
160
future_compat_lint ( ) ;
@@ -173,7 +166,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
173
166
174
167
debug ! ( ?concrete, "is_const_evaluatable" ) ;
175
168
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 ( ) {
177
170
true => NotConstEvaluatable :: MentionsInfer ,
178
171
false => NotConstEvaluatable :: MentionsParam ,
179
172
} ) ,
@@ -198,23 +191,22 @@ pub struct AbstractConst<'tcx> {
198
191
pub substs : SubstsRef < ' tcx > ,
199
192
}
200
193
201
- impl AbstractConst < ' tcx > {
194
+ impl < ' tcx > AbstractConst < ' tcx > {
202
195
pub fn new (
203
196
tcx : TyCtxt < ' tcx > ,
204
- def : ty:: WithOptConstParam < DefId > ,
205
- substs : SubstsRef < ' tcx > ,
197
+ uv : ty:: Unevaluated < ' tcx > ,
206
198
) -> 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 ) } ) )
210
202
}
211
203
212
204
pub fn from_const (
213
205
tcx : TyCtxt < ' tcx > ,
214
206
ct : & ty:: Const < ' tcx > ,
215
207
) -> Result < Option < AbstractConst < ' tcx > > , ErrorReported > {
216
208
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) ,
218
210
ty:: ConstKind :: Error ( _) => Err ( ErrorReported ) ,
219
211
_ => Ok ( None ) ,
220
212
}
@@ -564,14 +556,11 @@ pub(super) fn mir_abstract_const<'tcx>(
564
556
565
557
pub ( super ) fn try_unify_abstract_consts < ' tcx > (
566
558
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 > ) ,
571
560
) -> bool {
572
561
( || {
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) ? {
575
564
return Ok ( try_unify ( tcx, a, b) ) ;
576
565
}
577
566
}
0 commit comments