@@ -27,10 +27,11 @@ use super::util;
27
27
use hir:: def_id:: DefId ;
28
28
use infer:: InferOk ;
29
29
use infer:: type_variable:: TypeVariableOrigin ;
30
+ use middle:: const_val:: ConstVal ;
30
31
use rustc_data_structures:: snapshot_map:: { Snapshot , SnapshotMap } ;
31
32
use syntax:: ast;
32
33
use syntax:: symbol:: Symbol ;
33
- use ty:: subst:: Subst ;
34
+ use ty:: subst:: { Subst , Substs } ;
34
35
use ty:: { self , ToPredicate , ToPolyTraitRef , Ty , TyCtxt } ;
35
36
use ty:: fold:: { TypeFoldable , TypeFolder } ;
36
37
use util:: common:: FN_OUTPUT_NAME ;
@@ -260,7 +261,7 @@ impl<'a, 'b, 'gcx, 'tcx> AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> {
260
261
fn fold < T : TypeFoldable < ' tcx > > ( & mut self , value : & T ) -> T {
261
262
let value = self . selcx . infcx ( ) . resolve_type_vars_if_possible ( value) ;
262
263
263
- if !value. has_projection_types ( ) {
264
+ if !value. has_projections ( ) {
264
265
value. clone ( )
265
266
} else {
266
267
value. fold_with ( self )
@@ -332,6 +333,39 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
332
333
}
333
334
}
334
335
}
336
+
337
+ fn fold_const ( & mut self , constant : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
338
+ if let ConstVal :: Unevaluated ( def_id, substs) = constant. val {
339
+ if substs. needs_infer ( ) {
340
+ let identity_substs = Substs :: identity_for_item ( self . tcx ( ) , def_id) ;
341
+ let data = self . param_env . and ( ( def_id, identity_substs) ) ;
342
+ match self . tcx ( ) . lift_to_global ( & data) {
343
+ Some ( data) => {
344
+ match self . tcx ( ) . const_eval ( data) {
345
+ Ok ( evaluated) => {
346
+ let evaluated = evaluated. subst ( self . tcx ( ) , substs) ;
347
+ return self . fold_const ( evaluated) ;
348
+ }
349
+ Err ( _) => { }
350
+ }
351
+ }
352
+ None => { }
353
+ }
354
+ } else {
355
+ let data = self . param_env . and ( ( def_id, substs) ) ;
356
+ match self . tcx ( ) . lift_to_global ( & data) {
357
+ Some ( data) => {
358
+ match self . tcx ( ) . const_eval ( data) {
359
+ Ok ( evaluated) => return self . fold_const ( evaluated) ,
360
+ Err ( _) => { }
361
+ }
362
+ }
363
+ None => { }
364
+ }
365
+ }
366
+ }
367
+ constant
368
+ }
335
369
}
336
370
337
371
#[ derive( Clone ) ]
@@ -504,7 +538,7 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
504
538
depth,
505
539
obligations) ;
506
540
507
- let result = if projected_ty. has_projection_types ( ) {
541
+ let result = if projected_ty. has_projections ( ) {
508
542
let mut normalizer = AssociatedTypeNormalizer :: new ( selcx,
509
543
param_env,
510
544
cause,
0 commit comments