@@ -739,8 +739,57 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
739
739
intravisit:: NestedVisitorMap :: All ( & self . map )
740
740
}
741
741
742
- fn visit_item ( & mut self , item : & ' hir hir:: Item ) {
742
+ fn visit_item ( & mut self , mut item : & ' hir hir:: Item ) {
743
743
let is_public = item. vis . node . is_pub ( ) ;
744
+ if let hir:: ItemKind :: Use ( ref path, hir:: UseKind :: Single ) = item. node {
745
+ if is_public {
746
+ if let Some ( node) = self . map . get_if_local ( path. def . def_id ( ) ) {
747
+ // load doctests from the actual item, not the use statement
748
+ // TODO(misdreavus): this will run some doctests multiple times if an item is
749
+ // re-exported multiple times (say, into a prelude)
750
+ match node {
751
+ // if we've re-exported an item, continue with the new item, using the
752
+ // exported visibility
753
+ hir:: Node :: Item ( new_item) => item = new_item,
754
+ // forward anything else we handle specially to our visitor
755
+ hir:: Node :: TraitItem ( item) => {
756
+ self . visit_trait_item ( item) ;
757
+ return ;
758
+ }
759
+ hir:: Node :: ImplItem ( item) => {
760
+ self . visit_impl_item ( item) ;
761
+ return ;
762
+ }
763
+ hir:: Node :: ForeignItem ( item) => {
764
+ self . visit_foreign_item ( item) ;
765
+ return ;
766
+ }
767
+ hir:: Node :: Field ( f) => {
768
+ self . visit_struct_field ( f) ;
769
+ return ;
770
+ }
771
+ hir:: Node :: MacroDef ( def) => {
772
+ self . visit_macro_def ( def) ;
773
+ return ;
774
+ }
775
+ hir:: Node :: Variant ( v) => {
776
+ // we need the Generics and NodeId of the parent enum
777
+ let variant_node_id =
778
+ self . map . local_def_id_to_node_id ( path. def . def_id ( ) . to_local ( ) ) ;
779
+ let enum_node_id = self . map . get_parent ( variant_node_id) ;
780
+ let enum_def_id = self . map . local_def_id ( enum_node_id) ;
781
+ let generics = self . map . get_generics ( enum_def_id)
782
+ . expect ( "enums always have a Generics struct" ) ;
783
+
784
+ self . visit_variant ( v, generics, enum_node_id) ;
785
+ return ;
786
+ }
787
+ // we don't care about any other kind of node, so bail early
788
+ _ => return ,
789
+ }
790
+ }
791
+ }
792
+ }
744
793
745
794
let name = if let hir:: ItemKind :: Impl ( .., ref ty, _) = item. node {
746
795
self . map . node_to_pretty_string ( ty. id )
0 commit comments