@@ -2059,55 +2059,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2059
2059
}
2060
2060
2061
2061
pub fn associated_item ( self , def_id : DefId ) -> AssociatedItem {
2062
- if !def_id. is_local ( ) {
2063
- return queries:: associated_item:: get ( self , DUMMY_SP , def_id) ;
2064
- }
2065
-
2066
- self . maps . associated_item . memoize ( def_id, || {
2067
- // When the user asks for a given associated item, we
2068
- // always go ahead and convert all the associated items in
2069
- // the container. Note that we are also careful only to
2070
- // ever register a read on the *container* of the assoc
2071
- // item, not the assoc item itself. This prevents changes
2072
- // in the details of an item (for example, the type to
2073
- // which an associated type is bound) from contaminating
2074
- // those tasks that just need to scan the names of items
2075
- // and so forth.
2076
-
2077
- let id = self . hir . as_local_node_id ( def_id) . unwrap ( ) ;
2078
- let parent_id = self . hir . get_parent ( id) ;
2079
- let parent_def_id = self . hir . local_def_id ( parent_id) ;
2080
- let parent_item = self . hir . expect_item ( parent_id) ;
2081
- match parent_item. node {
2082
- hir:: ItemImpl ( .., ref impl_trait_ref, _, ref impl_item_refs) => {
2083
- for impl_item_ref in impl_item_refs {
2084
- let assoc_item =
2085
- self . associated_item_from_impl_item_ref ( parent_def_id,
2086
- impl_trait_ref. is_some ( ) ,
2087
- impl_item_ref) ;
2088
- self . maps . associated_item . borrow_mut ( )
2089
- . insert ( assoc_item. def_id , assoc_item) ;
2090
- }
2091
- }
2092
-
2093
- hir:: ItemTrait ( .., ref trait_item_refs) => {
2094
- for trait_item_ref in trait_item_refs {
2095
- let assoc_item =
2096
- self . associated_item_from_trait_item_ref ( parent_def_id, trait_item_ref) ;
2097
- self . maps . associated_item . borrow_mut ( )
2098
- . insert ( assoc_item. def_id , assoc_item) ;
2099
- }
2100
- }
2101
-
2102
- ref r => {
2103
- panic ! ( "unexpected container of associated items: {:?}" , r)
2104
- }
2105
- }
2106
-
2107
- // memoize wants us to return something, so return
2108
- // the one we generated for this def-id
2109
- * self . maps . associated_item . borrow ( ) . get ( & def_id) . unwrap ( )
2110
- } )
2062
+ queries:: associated_item:: get ( self , DUMMY_SP , def_id)
2111
2063
}
2112
2064
2113
2065
fn associated_item_from_trait_item_ref ( self ,
@@ -2643,3 +2595,45 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2643
2595
}
2644
2596
}
2645
2597
}
2598
+
2599
+ fn associated_item < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId )
2600
+ -> AssociatedItem
2601
+ {
2602
+ let id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
2603
+ let parent_id = tcx. hir . get_parent ( id) ;
2604
+ let parent_def_id = tcx. hir . local_def_id ( parent_id) ;
2605
+ let parent_item = tcx. hir . expect_item ( parent_id) ;
2606
+ match parent_item. node {
2607
+ hir:: ItemImpl ( .., ref impl_trait_ref, _, ref impl_item_refs) => {
2608
+ if let Some ( impl_item_ref) = impl_item_refs. iter ( ) . find ( |i| i. id . node_id == id) {
2609
+ let assoc_item =
2610
+ tcx. associated_item_from_impl_item_ref ( parent_def_id,
2611
+ impl_trait_ref. is_some ( ) ,
2612
+ impl_item_ref) ;
2613
+ debug_assert_eq ! ( assoc_item. def_id, def_id) ;
2614
+ return assoc_item;
2615
+ }
2616
+ }
2617
+
2618
+ hir:: ItemTrait ( .., ref trait_item_refs) => {
2619
+ if let Some ( trait_item_ref) = trait_item_refs. iter ( ) . find ( |i| i. id . node_id == id) {
2620
+ let assoc_item =
2621
+ tcx. associated_item_from_trait_item_ref ( parent_def_id, trait_item_ref) ;
2622
+ debug_assert_eq ! ( assoc_item. def_id, def_id) ;
2623
+ return assoc_item;
2624
+ }
2625
+ }
2626
+
2627
+ ref r => {
2628
+ panic ! ( "unexpected container of associated items: {:?}" , r)
2629
+ }
2630
+ }
2631
+ panic ! ( "associated item not found for def_id: {:?}" , def_id) ;
2632
+ }
2633
+
2634
+ pub fn provide ( providers : & mut ty:: maps:: Providers ) {
2635
+ * providers = ty:: maps:: Providers {
2636
+ associated_item,
2637
+ ..* providers
2638
+ } ;
2639
+ }
0 commit comments