@@ -1523,23 +1523,32 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15231523 } )
15241524 }
15251525
1526- fn encode_info_for_item ( & mut self , def_id : DefId , item : & ' tcx hir:: Item < ' tcx > ) {
1526+ fn encode_info_for_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
15271527 let tcx = self . tcx ;
1528-
1528+ let def_id = item . owner_id . to_def_id ( ) ;
15291529 debug ! ( "EncodeContext::encode_info_for_item({:?})" , def_id) ;
15301530
1531+ let record_associated_item_def_ids = |this : & mut Self , def_ids : & [ DefId ] | {
1532+ record_array ! ( this. tables. children[ def_id] <- def_ids. iter( ) . map( |& def_id| {
1533+ assert!( def_id. is_local( ) ) ;
1534+ def_id. index
1535+ } ) )
1536+ } ;
1537+
15311538 match item. kind {
15321539 hir:: ItemKind :: Fn ( ref sig, .., body) => {
15331540 self . tables . asyncness . set_some ( def_id. index , sig. header . asyncness ) ;
15341541 record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
15351542 self . tables . constness . set_some ( def_id. index , sig. header . constness ) ;
1543+ record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1544+ self . tables . is_intrinsic . set ( def_id. index , tcx. is_intrinsic ( def_id) ) ;
15361545 }
15371546 hir:: ItemKind :: Macro ( ref macro_def, _) => {
15381547 self . tables . is_macro_rules . set ( def_id. index , macro_def. macro_rules ) ;
15391548 record ! ( self . tables. macro_definition[ def_id] <- & * macro_def. body) ;
15401549 }
15411550 hir:: ItemKind :: Mod ( ref m) => {
1542- return self . encode_info_for_mod ( item. owner_id . def_id , m) ;
1551+ self . encode_info_for_mod ( item. owner_id . def_id , m) ;
15431552 }
15441553 hir:: ItemKind :: OpaqueTy ( ref opaque) => {
15451554 self . encode_explicit_item_bounds ( def_id) ;
@@ -1550,9 +1559,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15501559 hir:: ItemKind :: Impl ( hir:: Impl { defaultness, constness, .. } ) => {
15511560 self . tables . impl_defaultness . set_some ( def_id. index , * defaultness) ;
15521561 self . tables . constness . set_some ( def_id. index , * constness) ;
1562+ self . tables . impl_polarity . set_some ( def_id. index , self . tcx . impl_polarity ( def_id) ) ;
1563+
1564+ if let Some ( trait_ref) = self . tcx . impl_trait_ref ( def_id) {
1565+ record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
15531566
1554- let trait_ref = self . tcx . impl_trait_ref ( def_id) ;
1555- if let Some ( trait_ref) = trait_ref {
15561567 let trait_ref = trait_ref. skip_binder ( ) ;
15571568 let trait_def = self . tcx . trait_def ( trait_ref. def_id ) ;
15581569 if let Ok ( mut an) = trait_def. ancestors ( self . tcx , def_id) {
@@ -1570,71 +1581,34 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15701581 }
15711582 }
15721583
1573- let polarity = self . tcx . impl_polarity ( def_id) ;
1574- self . tables . impl_polarity . set_some ( def_id. index , polarity) ;
1584+ let associated_item_def_ids = self . tcx . associated_item_def_ids ( def_id) ;
1585+ record_associated_item_def_ids ( self , associated_item_def_ids) ;
1586+ for & trait_item_def_id in associated_item_def_ids {
1587+ self . encode_info_for_impl_item ( trait_item_def_id) ;
1588+ }
15751589 }
15761590 hir:: ItemKind :: Trait ( ..) => {
1577- let trait_def = self . tcx . trait_def ( def_id) ;
1578- record ! ( self . tables. trait_def[ def_id] <- trait_def) ;
1591+ record ! ( self . tables. trait_def[ def_id] <- self . tcx. trait_def( def_id) ) ;
1592+
1593+ let associated_item_def_ids = self . tcx . associated_item_def_ids ( def_id) ;
1594+ record_associated_item_def_ids ( self , associated_item_def_ids) ;
1595+ for & item_def_id in associated_item_def_ids {
1596+ self . encode_info_for_trait_item ( item_def_id) ;
1597+ }
15791598 }
15801599 hir:: ItemKind :: TraitAlias ( ..) => {
1581- let trait_def = self . tcx . trait_def ( def_id) ;
1582- record ! ( self . tables. trait_def[ def_id] <- trait_def) ;
1583- }
1584- hir:: ItemKind :: ExternCrate ( _) | hir:: ItemKind :: Use ( ..) => {
1585- bug ! ( "cannot encode info for item {:?}" , item)
1600+ record ! ( self . tables. trait_def[ def_id] <- self . tcx. trait_def( def_id) ) ;
15861601 }
1587- hir:: ItemKind :: Static ( ..)
1602+ hir:: ItemKind :: ExternCrate ( _)
1603+ | hir:: ItemKind :: Use ( ..)
1604+ | hir:: ItemKind :: Static ( ..)
15881605 | hir:: ItemKind :: Const ( ..)
15891606 | hir:: ItemKind :: Enum ( ..)
15901607 | hir:: ItemKind :: Struct ( ..)
15911608 | hir:: ItemKind :: Union ( ..)
15921609 | hir:: ItemKind :: ForeignMod { .. }
15931610 | hir:: ItemKind :: GlobalAsm ( ..)
15941611 | hir:: ItemKind :: TyAlias ( ..) => { }
1595- } ;
1596- // FIXME(eddyb) there should be a nicer way to do this.
1597- match item. kind {
1598- hir:: ItemKind :: Impl { .. } | hir:: ItemKind :: Trait ( ..) => {
1599- let associated_item_def_ids = self . tcx . associated_item_def_ids ( def_id) ;
1600- record_array ! ( self . tables. children[ def_id] <-
1601- associated_item_def_ids. iter( ) . map( |& def_id| {
1602- assert!( def_id. is_local( ) ) ;
1603- def_id. index
1604- } )
1605- ) ;
1606- }
1607- _ => { }
1608- }
1609- if let hir:: ItemKind :: Fn ( ..) = item. kind {
1610- record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1611- self . tables . is_intrinsic . set ( def_id. index , tcx. is_intrinsic ( def_id) ) ;
1612- }
1613- if let hir:: ItemKind :: Impl { .. } = item. kind {
1614- if let Some ( trait_ref) = self . tcx . impl_trait_ref ( def_id) {
1615- record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
1616- }
1617- }
1618- // In some cases, along with the item itself, we also
1619- // encode some sub-items. Usually we want some info from the item
1620- // so it's easier to do that here then to wait until we would encounter
1621- // normally in the visitor walk.
1622- match item. kind {
1623- hir:: ItemKind :: Impl { .. } => {
1624- for & trait_item_def_id in
1625- self . tcx . associated_item_def_ids ( item. owner_id . to_def_id ( ) ) . iter ( )
1626- {
1627- self . encode_info_for_impl_item ( trait_item_def_id) ;
1628- }
1629- }
1630- hir:: ItemKind :: Trait ( ..) => {
1631- for & item_def_id in
1632- self . tcx . associated_item_def_ids ( item. owner_id . to_def_id ( ) ) . iter ( )
1633- {
1634- self . encode_info_for_trait_item ( item_def_id) ;
1635- }
1636- }
1637- _ => { }
16381612 }
16391613 }
16401614
@@ -2020,10 +1994,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
20201994 }
20211995 fn visit_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
20221996 intravisit:: walk_item ( self , item) ;
2023- match item. kind {
2024- hir:: ItemKind :: ExternCrate ( _) | hir:: ItemKind :: Use ( ..) => { } // ignore these
2025- _ => self . encode_info_for_item ( item. owner_id . to_def_id ( ) , item) ,
2026- }
1997+ self . encode_info_for_item ( item) ;
20271998 }
20281999 fn visit_foreign_item ( & mut self , ni : & ' tcx hir:: ForeignItem < ' tcx > ) {
20292000 intravisit:: walk_foreign_item ( self , ni) ;
0 commit comments