8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ use common:: * ;
11
12
use rustc:: hir:: def_id:: DefId ;
12
13
use rustc:: infer:: TransNormalize ;
14
+ use rustc:: ty:: fold:: { TypeFolder , TypeFoldable } ;
13
15
use rustc:: ty:: subst:: { Subst , Substs } ;
14
16
use rustc:: ty:: { self , Ty , TyCtxt } ;
15
- use common:: * ;
16
17
use rustc:: util:: ppaux;
17
-
18
+ use rustc :: util :: common :: MemoizationMap ;
18
19
use std:: fmt;
19
20
20
21
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
@@ -51,10 +52,8 @@ pub fn apply_param_substs<'a, 'tcx, T>(scx: &SharedCrateContext<'a, 'tcx>,
51
52
let tcx = scx. tcx ( ) ;
52
53
debug ! ( "apply_param_substs(param_substs={:?}, value={:?})" , param_substs, value) ;
53
54
let substituted = value. subst ( tcx, param_substs) ;
54
- debug ! ( "apply_param_substs: substituted={:?}{}" ,
55
- substituted,
56
- if substituted. has_projection_types( ) { " [needs projection]" } else { "" } ) ;
57
- tcx. normalize_associated_type ( & substituted)
55
+ let substituted = scx. tcx ( ) . erase_regions ( & substituted) ;
56
+ AssociatedTypeNormalizer :: new ( scx) . fold ( & substituted)
58
57
}
59
58
60
59
@@ -67,3 +66,39 @@ pub fn field_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
67
66
tcx. normalize_associated_type ( & f. ty ( tcx, param_substs) )
68
67
}
69
68
69
+ struct AssociatedTypeNormalizer < ' a , ' b : ' a , ' gcx : ' b > {
70
+ shared : & ' a SharedCrateContext < ' b , ' gcx > ,
71
+ }
72
+
73
+ impl < ' a , ' b , ' gcx > AssociatedTypeNormalizer < ' a , ' b , ' gcx > {
74
+ fn new ( shared : & ' a SharedCrateContext < ' b , ' gcx > ) -> Self {
75
+ AssociatedTypeNormalizer {
76
+ shared : shared,
77
+ }
78
+ }
79
+
80
+ fn fold < T : TypeFoldable < ' gcx > > ( & mut self , value : & T ) -> T {
81
+ if !value. has_projection_types ( ) {
82
+ value. clone ( )
83
+ } else {
84
+ value. fold_with ( self )
85
+ }
86
+ }
87
+ }
88
+
89
+ impl < ' a , ' b , ' gcx > TypeFolder < ' gcx , ' gcx > for AssociatedTypeNormalizer < ' a , ' b , ' gcx > {
90
+ fn tcx < ' c > ( & ' c self ) -> TyCtxt < ' c , ' gcx , ' gcx > {
91
+ self . shared . tcx ( )
92
+ }
93
+
94
+ fn fold_ty ( & mut self , ty : Ty < ' gcx > ) -> Ty < ' gcx > {
95
+ if !ty. has_projection_types ( ) {
96
+ ty
97
+ } else {
98
+ self . shared . project_cache ( ) . memoize ( ty, || {
99
+ debug ! ( "AssociatedTypeNormalizer: ty={:?}" , ty) ;
100
+ self . shared . tcx ( ) . normalize_associated_type ( & ty)
101
+ } )
102
+ }
103
+ }
104
+ }
0 commit comments