@@ -18,15 +18,17 @@ use rustc_hir::{AssocItemKind, HirIdSet, Node, PatKind};
18
18
use rustc_middle:: bug;
19
19
use rustc_middle:: hir:: map:: Map ;
20
20
use rustc_middle:: middle:: privacy:: { AccessLevel , AccessLevels } ;
21
+ use rustc_middle:: mir:: abstract_const:: Node as ACNode ;
21
22
use rustc_middle:: span_bug;
22
23
use rustc_middle:: ty:: fold:: TypeVisitor ;
23
24
use rustc_middle:: ty:: query:: Providers ;
24
- use rustc_middle:: ty:: subst:: InternalSubsts ;
25
- use rustc_middle:: ty:: { self , GenericParamDefKind , TraitRef , Ty , TyCtxt , TypeFoldable } ;
25
+ use rustc_middle:: ty:: subst:: { InternalSubsts , Subst } ;
26
+ use rustc_middle:: ty:: { self , Const , GenericParamDefKind , TraitRef , Ty , TyCtxt , TypeFoldable } ;
26
27
use rustc_session:: lint;
27
28
use rustc_span:: hygiene:: Transparency ;
28
29
use rustc_span:: symbol:: { kw, Ident } ;
29
30
use rustc_span:: Span ;
31
+ use rustc_trait_selection:: traits:: const_evaluatable:: { self , AbstractConst } ;
30
32
31
33
use std:: marker:: PhantomData ;
32
34
use std:: ops:: ControlFlow ;
@@ -112,19 +114,35 @@ where
112
114
ty. visit_with ( self )
113
115
}
114
116
ty:: PredicateKind :: RegionOutlives ( ..) => ControlFlow :: CONTINUE ,
115
- ty:: PredicateKind :: ConstEvaluatable ( .. )
117
+ ty:: PredicateKind :: ConstEvaluatable ( defs , substs )
116
118
if self . def_id_visitor . tcx ( ) . features ( ) . const_evaluatable_checked =>
117
119
{
118
- // FIXME(const_evaluatable_checked): If the constant used here depends on a
119
- // private function we may have to do something here...
120
- //
121
- // For now, let's just pretend that everything is fine.
120
+ let tcx = self . def_id_visitor . tcx ( ) ;
121
+ if let Ok ( Some ( ct ) ) = AbstractConst :: new ( tcx , defs , substs ) {
122
+ self . visit_abstract_const_expr ( tcx , ct ) ? ;
123
+ }
122
124
ControlFlow :: CONTINUE
123
125
}
124
126
_ => bug ! ( "unexpected predicate: {:?}" , predicate) ,
125
127
}
126
128
}
127
129
130
+ fn visit_abstract_const_expr (
131
+ & mut self ,
132
+ tcx : TyCtxt < ' tcx > ,
133
+ ct : AbstractConst < ' tcx > ,
134
+ ) -> ControlFlow < V :: BreakTy > {
135
+ const_evaluatable:: walk_abstract_const ( tcx, ct, |node| match node {
136
+ ACNode :: Leaf ( leaf) => {
137
+ let leaf = leaf. subst ( tcx, ct. substs ) ;
138
+ self . visit_const ( leaf)
139
+ }
140
+ ACNode :: Binop ( ..) | ACNode :: UnaryOp ( ..) | ACNode :: FunctionCall ( _, _) => {
141
+ ControlFlow :: CONTINUE
142
+ }
143
+ } )
144
+ }
145
+
128
146
fn visit_predicates (
129
147
& mut self ,
130
148
predicates : ty:: GenericPredicates < ' tcx > ,
@@ -241,6 +259,15 @@ where
241
259
ty. super_visit_with ( self )
242
260
}
243
261
}
262
+
263
+ fn visit_const ( & mut self , c : & ' tcx Const < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
264
+ self . visit_ty ( c. ty ) ?;
265
+ let tcx = self . def_id_visitor . tcx ( ) ;
266
+ if let Ok ( Some ( ct) ) = AbstractConst :: from_const ( tcx, c) {
267
+ self . visit_abstract_const_expr ( tcx, ct) ?;
268
+ }
269
+ ControlFlow :: CONTINUE
270
+ }
244
271
}
245
272
246
273
fn min ( vis1 : ty:: Visibility , vis2 : ty:: Visibility , tcx : TyCtxt < ' _ > ) -> ty:: Visibility {
0 commit comments