@@ -2773,10 +2773,35 @@ fn clean_maybe_renamed_item<'tcx>(
27732773) -> Vec < Item > {
27742774 use hir:: ItemKind ;
27752775
2776- let def_id = item. owner_id . to_def_id ( ) ;
2777- let mut name = if renamed. is_some ( ) { renamed } else { cx. tcx . hir_opt_name ( item. hir_id ( ) ) } ;
2776+ fn get_name (
2777+ cx : & DocContext < ' _ > ,
2778+ item : & hir:: Item < ' _ > ,
2779+ renamed : Option < Symbol > ,
2780+ ) -> Option < Symbol > {
2781+ renamed. or_else ( || cx. tcx . hir_opt_name ( item. hir_id ( ) ) )
2782+ }
27782783
2784+ let def_id = item. owner_id . to_def_id ( ) ;
27792785 cx. with_param_env ( def_id, |cx| {
2786+ // These kinds of item either don't need a `name` or accept a `None` one so we handle them
2787+ // before.
2788+ match item. kind {
2789+ ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. owner_id . def_id , cx) ,
2790+ ItemKind :: Use ( path, kind) => {
2791+ return clean_use_statement (
2792+ item,
2793+ get_name ( cx, item, renamed) ,
2794+ path,
2795+ kind,
2796+ cx,
2797+ & mut FxHashSet :: default ( ) ,
2798+ ) ;
2799+ }
2800+ _ => { }
2801+ }
2802+
2803+ let mut name = get_name ( cx, item, renamed) . unwrap ( ) ;
2804+
27802805 let kind = match item. kind {
27812806 ItemKind :: Static ( _, ty, mutability, body_id) => StaticItem ( Static {
27822807 type_ : Box :: new ( clean_ty ( ty, cx) ) ,
@@ -2815,7 +2840,7 @@ fn clean_maybe_renamed_item<'tcx>(
28152840 item_type : Some ( type_) ,
28162841 } ) ) ,
28172842 item. owner_id . def_id . to_def_id ( ) ,
2818- name. unwrap ( ) ,
2843+ name,
28192844 import_id,
28202845 renamed,
28212846 ) ) ;
@@ -2838,17 +2863,14 @@ fn clean_maybe_renamed_item<'tcx>(
28382863 generics : clean_generics ( generics, cx) ,
28392864 fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
28402865 } ) ,
2841- ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. owner_id . def_id , cx) ,
28422866 ItemKind :: Macro ( _, macro_def, MacroKind :: Bang ) => MacroItem ( Macro {
2843- source : display_macro_source ( cx, name. unwrap ( ) , macro_def) ,
2867+ source : display_macro_source ( cx, name, macro_def) ,
28442868 macro_rules : macro_def. macro_rules ,
28452869 } ) ,
2846- ItemKind :: Macro ( _, _, macro_kind) => {
2847- clean_proc_macro ( item, name. as_mut ( ) . unwrap ( ) , macro_kind, cx)
2848- }
2870+ ItemKind :: Macro ( _, _, macro_kind) => clean_proc_macro ( item, & mut name, macro_kind, cx) ,
28492871 // proc macros can have a name set by attributes
28502872 ItemKind :: Fn { ref sig, generics, body : body_id, .. } => {
2851- clean_fn_or_proc_macro ( item, sig, generics, body_id, name. as_mut ( ) . unwrap ( ) , cx)
2873+ clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
28522874 }
28532875 ItemKind :: Trait ( _, _, _, generics, bounds, item_ids) => {
28542876 let items = item_ids
@@ -2864,10 +2886,7 @@ fn clean_maybe_renamed_item<'tcx>(
28642886 } ) )
28652887 }
28662888 ItemKind :: ExternCrate ( orig_name, _) => {
2867- return clean_extern_crate ( item, name. unwrap ( ) , orig_name, cx) ;
2868- }
2869- ItemKind :: Use ( path, kind) => {
2870- return clean_use_statement ( item, name, path, kind, cx, & mut FxHashSet :: default ( ) ) ;
2889+ return clean_extern_crate ( item, name, orig_name, cx) ;
28712890 }
28722891 _ => span_bug ! ( item. span, "not yet converted" ) ,
28732892 } ;
@@ -2876,7 +2895,7 @@ fn clean_maybe_renamed_item<'tcx>(
28762895 cx,
28772896 kind,
28782897 item. owner_id. def_id. to_def_id( ) ,
2879- name. unwrap ( ) ,
2898+ name,
28802899 import_id,
28812900 renamed,
28822901 ) ]
0 commit comments