@@ -2049,55 +2049,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2049
2049
}
2050
2050
2051
2051
pub fn associated_item ( self , def_id : DefId ) -> AssociatedItem {
2052
- if !def_id. is_local ( ) {
2053
- return queries:: associated_item:: get ( self , DUMMY_SP , def_id) ;
2054
- }
2055
-
2056
- self . maps . associated_item . memoize ( def_id, || {
2057
- // When the user asks for a given associated item, we
2058
- // always go ahead and convert all the associated items in
2059
- // the container. Note that we are also careful only to
2060
- // ever register a read on the *container* of the assoc
2061
- // item, not the assoc item itself. This prevents changes
2062
- // in the details of an item (for example, the type to
2063
- // which an associated type is bound) from contaminating
2064
- // those tasks that just need to scan the names of items
2065
- // and so forth.
2066
-
2067
- let id = self . hir . as_local_node_id ( def_id) . unwrap ( ) ;
2068
- let parent_id = self . hir . get_parent ( id) ;
2069
- let parent_def_id = self . hir . local_def_id ( parent_id) ;
2070
- let parent_item = self . hir . expect_item ( parent_id) ;
2071
- match parent_item. node {
2072
- hir:: ItemImpl ( .., ref impl_trait_ref, _, ref impl_item_refs) => {
2073
- for impl_item_ref in impl_item_refs {
2074
- let assoc_item =
2075
- self . associated_item_from_impl_item_ref ( parent_def_id,
2076
- impl_trait_ref. is_some ( ) ,
2077
- impl_item_ref) ;
2078
- self . maps . associated_item . borrow_mut ( )
2079
- . insert ( assoc_item. def_id , assoc_item) ;
2080
- }
2081
- }
2082
-
2083
- hir:: ItemTrait ( .., ref trait_item_refs) => {
2084
- for trait_item_ref in trait_item_refs {
2085
- let assoc_item =
2086
- self . associated_item_from_trait_item_ref ( parent_def_id, trait_item_ref) ;
2087
- self . maps . associated_item . borrow_mut ( )
2088
- . insert ( assoc_item. def_id , assoc_item) ;
2089
- }
2090
- }
2091
-
2092
- ref r => {
2093
- panic ! ( "unexpected container of associated items: {:?}" , r)
2094
- }
2095
- }
2096
-
2097
- // memoize wants us to return something, so return
2098
- // the one we generated for this def-id
2099
- * self . maps . associated_item . borrow ( ) . get ( & def_id) . unwrap ( )
2100
- } )
2052
+ queries:: associated_item:: get ( self , DUMMY_SP , def_id)
2101
2053
}
2102
2054
2103
2055
fn associated_item_from_trait_item_ref ( self ,
@@ -2623,3 +2575,47 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2623
2575
}
2624
2576
}
2625
2577
}
2578
+
2579
+ fn associated_item < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId )
2580
+ -> AssociatedItem
2581
+ {
2582
+ let id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
2583
+ let parent_id = tcx. hir . get_parent ( id) ;
2584
+ let parent_def_id = tcx. hir . local_def_id ( parent_id) ;
2585
+ let parent_item = tcx. hir . expect_item ( parent_id) ;
2586
+ match parent_item. node {
2587
+ hir:: ItemImpl ( .., ref impl_trait_ref, _, ref impl_item_refs) => {
2588
+ for impl_item_ref in impl_item_refs {
2589
+ let assoc_item =
2590
+ tcx. associated_item_from_impl_item_ref ( parent_def_id,
2591
+ impl_trait_ref. is_some ( ) ,
2592
+ impl_item_ref) ;
2593
+ if assoc_item. def_id == def_id {
2594
+ return assoc_item;
2595
+ }
2596
+ }
2597
+ }
2598
+
2599
+ hir:: ItemTrait ( .., ref trait_item_refs) => {
2600
+ for trait_item_ref in trait_item_refs {
2601
+ let assoc_item =
2602
+ tcx. associated_item_from_trait_item_ref ( parent_def_id, trait_item_ref) ;
2603
+ if assoc_item. def_id == def_id {
2604
+ return assoc_item;
2605
+ }
2606
+ }
2607
+ }
2608
+
2609
+ ref r => {
2610
+ panic ! ( "unexpected container of associated items: {:?}" , r)
2611
+ }
2612
+ }
2613
+ panic ! ( "associated item not found for def_id: {:?}" , def_id) ;
2614
+ }
2615
+
2616
+ pub fn provide ( providers : & mut ty:: maps:: Providers ) {
2617
+ * providers = ty:: maps:: Providers {
2618
+ associated_item,
2619
+ ..* providers
2620
+ } ;
2621
+ }
0 commit comments