2121#![ doc( rust_logo) ]
2222#![ feature( rustdoc_internals) ]
2323#![ feature( sized_hierarchy) ]
24+ #![ feature( trait_alias) ]
2425// tidy-alphabetical-end
2526
2627use std:: cell:: RefCell ;
@@ -45,6 +46,9 @@ pub mod context;
4546#[ deprecated( note = "please use `rustc_public::rustc_internal` instead" ) ]
4647pub mod rustc_internal { }
4748
49+ /// Trait alias for types that can be cached in [`Tables`].
50+ pub trait Cacheable = Copy + Debug + PartialEq + IndexedVal ;
51+
4852/// A container which is used for TLS.
4953pub struct Container < ' tcx , B : Bridge > {
5054 pub tables : RefCell < Tables < ' tcx , B > > ,
@@ -213,14 +217,14 @@ impl<'tcx, B: Bridge> Tables<'tcx, B> {
213217/// A trait defining types that are used to emulate rustc_public components, which is really
214218/// useful when programming in rustc_public-agnostic settings.
215219pub trait Bridge : Sized {
216- type DefId : Copy + Debug + PartialEq + IndexedVal ;
217- type AllocId : Copy + Debug + PartialEq + IndexedVal ;
218- type Span : Copy + Debug + PartialEq + IndexedVal ;
219- type Ty : Copy + Debug + PartialEq + IndexedVal ;
220- type InstanceDef : Copy + Debug + PartialEq + IndexedVal ;
221- type TyConstId : Copy + Debug + PartialEq + IndexedVal ;
222- type MirConstId : Copy + Debug + PartialEq + IndexedVal ;
223- type Layout : Copy + Debug + PartialEq + IndexedVal ;
220+ type DefId : Cacheable ;
221+ type AllocId : Cacheable ;
222+ type Span : Cacheable ;
223+ type Ty : Cacheable ;
224+ type InstanceDef : Cacheable ;
225+ type TyConstId : Cacheable ;
226+ type MirConstId : Cacheable ;
227+ type Layout : Cacheable ;
224228
225229 type Error : Error ;
226230 type CrateItem : CrateItem < Self > ;
@@ -266,17 +270,15 @@ impl<K, V> Default for IndexMap<K, V> {
266270 }
267271}
268272
269- impl < K : PartialEq + Hash + Eq , V : Copy + Debug + PartialEq + IndexedVal > IndexMap < K , V > {
273+ impl < K : PartialEq + Hash + Eq , V : Cacheable > IndexMap < K , V > {
270274 pub fn create_or_fetch ( & mut self , key : K ) -> V {
271275 let len = self . index_map . len ( ) ;
272276 let v = self . index_map . entry ( key) . or_insert ( V :: to_val ( len) ) ;
273277 * v
274278 }
275279}
276280
277- impl < K : PartialEq + Hash + Eq , V : Copy + Debug + PartialEq + IndexedVal > Index < V >
278- for IndexMap < K , V >
279- {
281+ impl < K : PartialEq + Hash + Eq , V : Cacheable > Index < V > for IndexMap < K , V > {
280282 type Output = K ;
281283
282284 fn index ( & self , index : V ) -> & Self :: Output {
0 commit comments