@@ -2797,10 +2797,35 @@ fn clean_maybe_renamed_item<'tcx>(
2797
2797
) -> Vec < Item > {
2798
2798
use hir:: ItemKind ;
2799
2799
2800
- let def_id = item. owner_id . to_def_id ( ) ;
2801
- let mut name = if renamed. is_some ( ) { renamed } else { cx. tcx . hir_opt_name ( item. hir_id ( ) ) } ;
2800
+ fn get_name (
2801
+ cx : & DocContext < ' _ > ,
2802
+ item : & hir:: Item < ' _ > ,
2803
+ renamed : Option < Symbol > ,
2804
+ ) -> Option < Symbol > {
2805
+ renamed. or_else ( || cx. tcx . hir_opt_name ( item. hir_id ( ) ) )
2806
+ }
2802
2807
2808
+ let def_id = item. owner_id . to_def_id ( ) ;
2803
2809
cx. with_param_env ( def_id, |cx| {
2810
+ // These kinds of item either don't need a `name` or accept a `None` one so we handle them
2811
+ // before.
2812
+ match item. kind {
2813
+ ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. owner_id . def_id , cx) ,
2814
+ ItemKind :: Use ( path, kind) => {
2815
+ return clean_use_statement (
2816
+ item,
2817
+ get_name ( cx, item, renamed) ,
2818
+ path,
2819
+ kind,
2820
+ cx,
2821
+ & mut FxHashSet :: default ( ) ,
2822
+ ) ;
2823
+ }
2824
+ _ => { }
2825
+ }
2826
+
2827
+ let mut name = get_name ( cx, item, renamed) . unwrap ( ) ;
2828
+
2804
2829
let kind = match item. kind {
2805
2830
ItemKind :: Static ( _, ty, mutability, body_id) => StaticItem ( Static {
2806
2831
type_ : Box :: new ( clean_ty ( ty, cx) ) ,
@@ -2839,7 +2864,7 @@ fn clean_maybe_renamed_item<'tcx>(
2839
2864
item_type : Some ( type_) ,
2840
2865
} ) ) ,
2841
2866
item. owner_id . def_id . to_def_id ( ) ,
2842
- name. unwrap ( ) ,
2867
+ name,
2843
2868
import_id,
2844
2869
renamed,
2845
2870
) ) ;
@@ -2862,17 +2887,14 @@ fn clean_maybe_renamed_item<'tcx>(
2862
2887
generics : clean_generics ( generics, cx) ,
2863
2888
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
2864
2889
} ) ,
2865
- ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. owner_id . def_id , cx) ,
2866
2890
ItemKind :: Macro ( _, macro_def, MacroKind :: Bang ) => MacroItem ( Macro {
2867
- source : display_macro_source ( cx, name. unwrap ( ) , macro_def) ,
2891
+ source : display_macro_source ( cx, name, macro_def) ,
2868
2892
macro_rules : macro_def. macro_rules ,
2869
2893
} ) ,
2870
- ItemKind :: Macro ( _, _, macro_kind) => {
2871
- clean_proc_macro ( item, name. as_mut ( ) . unwrap ( ) , macro_kind, cx)
2872
- }
2894
+ ItemKind :: Macro ( _, _, macro_kind) => clean_proc_macro ( item, & mut name, macro_kind, cx) ,
2873
2895
// proc macros can have a name set by attributes
2874
2896
ItemKind :: Fn { ref sig, generics, body : body_id, .. } => {
2875
- clean_fn_or_proc_macro ( item, sig, generics, body_id, name. as_mut ( ) . unwrap ( ) , cx)
2897
+ clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
2876
2898
}
2877
2899
ItemKind :: Trait ( _, _, _, generics, bounds, item_ids) => {
2878
2900
let items = item_ids
@@ -2888,10 +2910,7 @@ fn clean_maybe_renamed_item<'tcx>(
2888
2910
} ) )
2889
2911
}
2890
2912
ItemKind :: ExternCrate ( orig_name, _) => {
2891
- return clean_extern_crate ( item, name. unwrap ( ) , orig_name, cx) ;
2892
- }
2893
- ItemKind :: Use ( path, kind) => {
2894
- return clean_use_statement ( item, name, path, kind, cx, & mut FxHashSet :: default ( ) ) ;
2913
+ return clean_extern_crate ( item, name, orig_name, cx) ;
2895
2914
}
2896
2915
_ => span_bug ! ( item. span, "not yet converted" ) ,
2897
2916
} ;
@@ -2900,7 +2919,7 @@ fn clean_maybe_renamed_item<'tcx>(
2900
2919
cx,
2901
2920
kind,
2902
2921
item. owner_id. def_id. to_def_id( ) ,
2903
- name. unwrap ( ) ,
2922
+ name,
2904
2923
import_id,
2905
2924
renamed,
2906
2925
) ]
0 commit comments