@@ -2773,10 +2773,35 @@ fn clean_maybe_renamed_item<'tcx>(
2773
2773
) -> Vec < Item > {
2774
2774
use hir:: ItemKind ;
2775
2775
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
+ }
2778
2783
2784
+ let def_id = item. owner_id . to_def_id ( ) ;
2779
2785
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
+
2780
2805
let kind = match item. kind {
2781
2806
ItemKind :: Static ( _, ty, mutability, body_id) => StaticItem ( Static {
2782
2807
type_ : Box :: new ( clean_ty ( ty, cx) ) ,
@@ -2815,7 +2840,7 @@ fn clean_maybe_renamed_item<'tcx>(
2815
2840
item_type : Some ( type_) ,
2816
2841
} ) ) ,
2817
2842
item. owner_id . def_id . to_def_id ( ) ,
2818
- name. unwrap ( ) ,
2843
+ name,
2819
2844
import_id,
2820
2845
renamed,
2821
2846
) ) ;
@@ -2838,17 +2863,14 @@ fn clean_maybe_renamed_item<'tcx>(
2838
2863
generics : clean_generics ( generics, cx) ,
2839
2864
fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x, cx) ) . collect ( ) ,
2840
2865
} ) ,
2841
- ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. owner_id . def_id , cx) ,
2842
2866
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) ,
2844
2868
macro_rules : macro_def. macro_rules ,
2845
2869
} ) ,
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) ,
2849
2871
// proc macros can have a name set by attributes
2850
2872
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)
2852
2874
}
2853
2875
ItemKind :: Trait ( _, _, _, generics, bounds, item_ids) => {
2854
2876
let items = item_ids
@@ -2864,10 +2886,7 @@ fn clean_maybe_renamed_item<'tcx>(
2864
2886
} ) )
2865
2887
}
2866
2888
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) ;
2871
2890
}
2872
2891
_ => span_bug ! ( item. span, "not yet converted" ) ,
2873
2892
} ;
@@ -2876,7 +2895,7 @@ fn clean_maybe_renamed_item<'tcx>(
2876
2895
cx,
2877
2896
kind,
2878
2897
item. owner_id. def_id. to_def_id( ) ,
2879
- name. unwrap ( ) ,
2898
+ name,
2880
2899
import_id,
2881
2900
renamed,
2882
2901
) ]
0 commit comments