@@ -4,6 +4,7 @@ use crate::infer::canonical::Canonical;
44use crate :: mir;
55use crate :: traits;
66use crate :: ty:: fast_reject:: SimplifiedType ;
7+ use crate :: ty:: query:: caches:: DefaultCacheSelector ;
78use crate :: ty:: subst:: SubstsRef ;
89use crate :: ty:: { self , Ty , TyCtxt } ;
910use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LOCAL_CRATE } ;
@@ -12,7 +13,9 @@ use rustc_span::{Span, DUMMY_SP};
1213
1314/// The `Key` trait controls what types can legally be used as the key
1415/// for a query.
15- pub ( super ) trait Key {
16+ pub trait Key {
17+ type CacheSelector ;
18+
1619 /// Given an instance of this key, what crate is it referring to?
1720 /// This is used to find the provider.
1821 fn query_crate ( & self ) -> CrateNum ;
@@ -23,6 +26,8 @@ pub(super) trait Key {
2326}
2427
2528impl < ' tcx > Key for ty:: InstanceDef < ' tcx > {
29+ type CacheSelector = DefaultCacheSelector ;
30+
2631 fn query_crate ( & self ) -> CrateNum {
2732 LOCAL_CRATE
2833 }
@@ -33,6 +38,8 @@ impl<'tcx> Key for ty::InstanceDef<'tcx> {
3338}
3439
3540impl < ' tcx > Key for ty:: Instance < ' tcx > {
41+ type CacheSelector = DefaultCacheSelector ;
42+
3643 fn query_crate ( & self ) -> CrateNum {
3744 LOCAL_CRATE
3845 }
@@ -43,6 +50,8 @@ impl<'tcx> Key for ty::Instance<'tcx> {
4350}
4451
4552impl < ' tcx > Key for mir:: interpret:: GlobalId < ' tcx > {
53+ type CacheSelector = DefaultCacheSelector ;
54+
4655 fn query_crate ( & self ) -> CrateNum {
4756 self . instance . query_crate ( )
4857 }
@@ -53,6 +62,8 @@ impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
5362}
5463
5564impl < ' tcx > Key for mir:: interpret:: LitToConstInput < ' tcx > {
65+ type CacheSelector = DefaultCacheSelector ;
66+
5667 fn query_crate ( & self ) -> CrateNum {
5768 LOCAL_CRATE
5869 }
@@ -63,6 +74,8 @@ impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
6374}
6475
6576impl Key for CrateNum {
77+ type CacheSelector = DefaultCacheSelector ;
78+
6679 fn query_crate ( & self ) -> CrateNum {
6780 * self
6881 }
@@ -72,6 +85,8 @@ impl Key for CrateNum {
7285}
7386
7487impl Key for DefIndex {
88+ type CacheSelector = DefaultCacheSelector ;
89+
7590 fn query_crate ( & self ) -> CrateNum {
7691 LOCAL_CRATE
7792 }
@@ -81,6 +96,8 @@ impl Key for DefIndex {
8196}
8297
8398impl Key for DefId {
99+ type CacheSelector = DefaultCacheSelector ;
100+
84101 fn query_crate ( & self ) -> CrateNum {
85102 self . krate
86103 }
@@ -90,6 +107,8 @@ impl Key for DefId {
90107}
91108
92109impl Key for ( DefId , DefId ) {
110+ type CacheSelector = DefaultCacheSelector ;
111+
93112 fn query_crate ( & self ) -> CrateNum {
94113 self . 0 . krate
95114 }
@@ -99,6 +118,8 @@ impl Key for (DefId, DefId) {
99118}
100119
101120impl Key for ( CrateNum , DefId ) {
121+ type CacheSelector = DefaultCacheSelector ;
122+
102123 fn query_crate ( & self ) -> CrateNum {
103124 self . 0
104125 }
@@ -108,6 +129,8 @@ impl Key for (CrateNum, DefId) {
108129}
109130
110131impl Key for ( DefId , SimplifiedType ) {
132+ type CacheSelector = DefaultCacheSelector ;
133+
111134 fn query_crate ( & self ) -> CrateNum {
112135 self . 0 . krate
113136 }
@@ -117,6 +140,8 @@ impl Key for (DefId, SimplifiedType) {
117140}
118141
119142impl < ' tcx > Key for SubstsRef < ' tcx > {
143+ type CacheSelector = DefaultCacheSelector ;
144+
120145 fn query_crate ( & self ) -> CrateNum {
121146 LOCAL_CRATE
122147 }
@@ -126,6 +151,8 @@ impl<'tcx> Key for SubstsRef<'tcx> {
126151}
127152
128153impl < ' tcx > Key for ( DefId , SubstsRef < ' tcx > ) {
154+ type CacheSelector = DefaultCacheSelector ;
155+
129156 fn query_crate ( & self ) -> CrateNum {
130157 self . 0 . krate
131158 }
@@ -135,6 +162,8 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
135162}
136163
137164impl < ' tcx > Key for ( ty:: ParamEnv < ' tcx > , ty:: PolyTraitRef < ' tcx > ) {
165+ type CacheSelector = DefaultCacheSelector ;
166+
138167 fn query_crate ( & self ) -> CrateNum {
139168 self . 1 . def_id ( ) . krate
140169 }
@@ -144,6 +173,8 @@ impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
144173}
145174
146175impl < ' tcx > Key for ( & ' tcx ty:: Const < ' tcx > , mir:: Field ) {
176+ type CacheSelector = DefaultCacheSelector ;
177+
147178 fn query_crate ( & self ) -> CrateNum {
148179 LOCAL_CRATE
149180 }
@@ -153,6 +184,8 @@ impl<'tcx> Key for (&'tcx ty::Const<'tcx>, mir::Field) {
153184}
154185
155186impl < ' tcx > Key for ty:: PolyTraitRef < ' tcx > {
187+ type CacheSelector = DefaultCacheSelector ;
188+
156189 fn query_crate ( & self ) -> CrateNum {
157190 self . def_id ( ) . krate
158191 }
@@ -162,6 +195,8 @@ impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
162195}
163196
164197impl < ' tcx > Key for & ' tcx ty:: Const < ' tcx > {
198+ type CacheSelector = DefaultCacheSelector ;
199+
165200 fn query_crate ( & self ) -> CrateNum {
166201 LOCAL_CRATE
167202 }
@@ -171,6 +206,8 @@ impl<'tcx> Key for &'tcx ty::Const<'tcx> {
171206}
172207
173208impl < ' tcx > Key for Ty < ' tcx > {
209+ type CacheSelector = DefaultCacheSelector ;
210+
174211 fn query_crate ( & self ) -> CrateNum {
175212 LOCAL_CRATE
176213 }
@@ -180,6 +217,8 @@ impl<'tcx> Key for Ty<'tcx> {
180217}
181218
182219impl < ' tcx > Key for ty:: ParamEnv < ' tcx > {
220+ type CacheSelector = DefaultCacheSelector ;
221+
183222 fn query_crate ( & self ) -> CrateNum {
184223 LOCAL_CRATE
185224 }
@@ -189,6 +228,8 @@ impl<'tcx> Key for ty::ParamEnv<'tcx> {
189228}
190229
191230impl < ' tcx , T : Key > Key for ty:: ParamEnvAnd < ' tcx , T > {
231+ type CacheSelector = DefaultCacheSelector ;
232+
192233 fn query_crate ( & self ) -> CrateNum {
193234 self . value . query_crate ( )
194235 }
@@ -198,6 +239,8 @@ impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
198239}
199240
200241impl < ' tcx > Key for traits:: Environment < ' tcx > {
242+ type CacheSelector = DefaultCacheSelector ;
243+
201244 fn query_crate ( & self ) -> CrateNum {
202245 LOCAL_CRATE
203246 }
@@ -207,6 +250,8 @@ impl<'tcx> Key for traits::Environment<'tcx> {
207250}
208251
209252impl Key for Symbol {
253+ type CacheSelector = DefaultCacheSelector ;
254+
210255 fn query_crate ( & self ) -> CrateNum {
211256 LOCAL_CRATE
212257 }
@@ -218,6 +263,8 @@ impl Key for Symbol {
218263/// Canonical query goals correspond to abstract trait operations that
219264/// are not tied to any crate in particular.
220265impl < ' tcx , T > Key for Canonical < ' tcx , T > {
266+ type CacheSelector = DefaultCacheSelector ;
267+
221268 fn query_crate ( & self ) -> CrateNum {
222269 LOCAL_CRATE
223270 }
@@ -228,6 +275,8 @@ impl<'tcx, T> Key for Canonical<'tcx, T> {
228275}
229276
230277impl Key for ( Symbol , u32 , u32 ) {
278+ type CacheSelector = DefaultCacheSelector ;
279+
231280 fn query_crate ( & self ) -> CrateNum {
232281 LOCAL_CRATE
233282 }
0 commit comments