@@ -1523,23 +1523,32 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1523
1523
} )
1524
1524
}
1525
1525
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 > ) {
1527
1527
let tcx = self . tcx ;
1528
-
1528
+ let def_id = item . owner_id . to_def_id ( ) ;
1529
1529
debug ! ( "EncodeContext::encode_info_for_item({:?})" , def_id) ;
1530
1530
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
+
1531
1538
match item. kind {
1532
1539
hir:: ItemKind :: Fn ( ref sig, .., body) => {
1533
1540
self . tables . asyncness . set_some ( def_id. index , sig. header . asyncness ) ;
1534
1541
record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
1535
1542
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) ) ;
1536
1545
}
1537
1546
hir:: ItemKind :: Macro ( ref macro_def, _) => {
1538
1547
self . tables . is_macro_rules . set ( def_id. index , macro_def. macro_rules ) ;
1539
1548
record ! ( self . tables. macro_definition[ def_id] <- & * macro_def. body) ;
1540
1549
}
1541
1550
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) ;
1543
1552
}
1544
1553
hir:: ItemKind :: OpaqueTy ( ref opaque) => {
1545
1554
self . encode_explicit_item_bounds ( def_id) ;
@@ -1550,9 +1559,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1550
1559
hir:: ItemKind :: Impl ( hir:: Impl { defaultness, constness, .. } ) => {
1551
1560
self . tables . impl_defaultness . set_some ( def_id. index , * defaultness) ;
1552
1561
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) ;
1553
1566
1554
- let trait_ref = self . tcx . impl_trait_ref ( def_id) ;
1555
- if let Some ( trait_ref) = trait_ref {
1556
1567
let trait_ref = trait_ref. skip_binder ( ) ;
1557
1568
let trait_def = self . tcx . trait_def ( trait_ref. def_id ) ;
1558
1569
if let Ok ( mut an) = trait_def. ancestors ( self . tcx , def_id) {
@@ -1570,71 +1581,34 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1570
1581
}
1571
1582
}
1572
1583
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
+ }
1575
1589
}
1576
1590
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
+ }
1579
1598
}
1580
1599
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) ) ;
1586
1601
}
1587
- hir:: ItemKind :: Static ( ..)
1602
+ hir:: ItemKind :: ExternCrate ( _)
1603
+ | hir:: ItemKind :: Use ( ..)
1604
+ | hir:: ItemKind :: Static ( ..)
1588
1605
| hir:: ItemKind :: Const ( ..)
1589
1606
| hir:: ItemKind :: Enum ( ..)
1590
1607
| hir:: ItemKind :: Struct ( ..)
1591
1608
| hir:: ItemKind :: Union ( ..)
1592
1609
| hir:: ItemKind :: ForeignMod { .. }
1593
1610
| hir:: ItemKind :: GlobalAsm ( ..)
1594
1611
| 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
- _ => { }
1638
1612
}
1639
1613
}
1640
1614
@@ -2020,10 +1994,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
2020
1994
}
2021
1995
fn visit_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
2022
1996
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) ;
2027
1998
}
2028
1999
fn visit_foreign_item ( & mut self , ni : & ' tcx hir:: ForeignItem < ' tcx > ) {
2029
2000
intravisit:: walk_foreign_item ( self , ni) ;
0 commit comments