@@ -117,16 +117,22 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
117
117
hir:: ItemKind :: Use ( path, kind) => {
118
118
let hir:: UsePath { segments, span, .. } = * path;
119
119
let path = hir:: Path { segments, res : * res, span } ;
120
- clean_use_statement_inner ( import, name, & path, kind, cx, & mut Default :: default ( ) )
120
+ clean_use_statement_inner (
121
+ import,
122
+ Some ( name) ,
123
+ & path,
124
+ kind,
125
+ cx,
126
+ & mut Default :: default ( ) ,
127
+ )
121
128
}
122
129
_ => unreachable ! ( ) ,
123
130
}
124
131
} ) ) ;
125
132
items. extend ( doc. items . values ( ) . flat_map ( |( item, renamed, _) | {
126
133
// Now we actually lower the imports, skipping everything else.
127
134
if let hir:: ItemKind :: Use ( path, hir:: UseKind :: Glob ) = item. kind {
128
- let name = renamed. unwrap_or ( kw:: Empty ) ; // using kw::Empty is a bit of a hack
129
- clean_use_statement ( item, name, path, hir:: UseKind :: Glob , cx, & mut inserted)
135
+ clean_use_statement ( item, * renamed, path, hir:: UseKind :: Glob , cx, & mut inserted)
130
136
} else {
131
137
// skip everything else
132
138
Vec :: new ( )
@@ -1072,10 +1078,10 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
1072
1078
..
1073
1079
} = param
1074
1080
{
1075
- func. decl
1076
- . inputs
1077
- . values
1078
- . insert ( a . get ( ) as _ , Argument { name , type_ : * ty , is_const : true } ) ;
1081
+ func. decl . inputs . values . insert (
1082
+ a . get ( ) as _ ,
1083
+ Argument { name : Some ( name ) , type_ : * ty , is_const : true } ,
1084
+ ) ;
1079
1085
} else {
1080
1086
panic ! ( "unexpected non const in position {pos}" ) ;
1081
1087
}
@@ -1132,9 +1138,9 @@ fn clean_args_from_types_and_names<'tcx>(
1132
1138
// If at least one argument has a name, use `_` as the name of unnamed
1133
1139
// arguments. Otherwise omit argument names.
1134
1140
let default_name = if idents. iter ( ) . any ( |ident| nonempty_name ( ident) . is_some ( ) ) {
1135
- kw:: Underscore
1141
+ Some ( kw:: Underscore )
1136
1142
} else {
1137
- kw :: Empty
1143
+ None
1138
1144
} ;
1139
1145
1140
1146
Arguments {
@@ -1143,7 +1149,7 @@ fn clean_args_from_types_and_names<'tcx>(
1143
1149
. enumerate ( )
1144
1150
. map ( |( i, ty) | Argument {
1145
1151
type_ : clean_ty ( ty, cx) ,
1146
- name : idents. get ( i) . and_then ( nonempty_name) . unwrap_or ( default_name) ,
1152
+ name : idents. get ( i) . and_then ( nonempty_name) . or ( default_name) ,
1147
1153
is_const : false ,
1148
1154
} )
1149
1155
. collect ( ) ,
@@ -1162,7 +1168,7 @@ fn clean_args_from_types_and_body_id<'tcx>(
1162
1168
. iter ( )
1163
1169
. zip ( body. params )
1164
1170
. map ( |( ty, param) | Argument {
1165
- name : name_from_pat ( param. pat ) ,
1171
+ name : Some ( name_from_pat ( param. pat ) ) ,
1166
1172
type_ : clean_ty ( ty, cx) ,
1167
1173
is_const : false ,
1168
1174
} )
@@ -1218,11 +1224,11 @@ fn clean_poly_fn_sig<'tcx>(
1218
1224
. iter ( )
1219
1225
. map ( |t| Argument {
1220
1226
type_ : clean_middle_ty ( t. map_bound ( |t| * t) , cx, None , None ) ,
1221
- name : if let Some ( Some ( ident) ) = names. next ( ) {
1227
+ name : Some ( if let Some ( Some ( ident) ) = names. next ( ) {
1222
1228
ident. name
1223
1229
} else {
1224
1230
kw:: Underscore
1225
- } ,
1231
+ } ) ,
1226
1232
is_const : false ,
1227
1233
} )
1228
1234
. collect ( ) ,
@@ -2792,10 +2798,7 @@ fn clean_maybe_renamed_item<'tcx>(
2792
2798
use hir:: ItemKind ;
2793
2799
2794
2800
let def_id = item. owner_id . to_def_id ( ) ;
2795
- let mut name = renamed. unwrap_or_else ( || {
2796
- // FIXME: using kw::Empty is a bit of a hack
2797
- cx. tcx . hir_opt_name ( item. hir_id ( ) ) . unwrap_or ( kw:: Empty )
2798
- } ) ;
2801
+ let mut name = if renamed. is_some ( ) { renamed } else { cx. tcx . hir_opt_name ( item. hir_id ( ) ) } ;
2799
2802
2800
2803
cx. with_param_env ( def_id, |cx| {
2801
2804
let kind = match item. kind {
@@ -2836,7 +2839,7 @@ fn clean_maybe_renamed_item<'tcx>(
2836
2839
item_type : Some ( type_) ,
2837
2840
} ) ) ,
2838
2841
item. owner_id . def_id . to_def_id ( ) ,
2839
- name,
2842
+ name. unwrap ( ) ,
2840
2843
import_id,
2841
2844
renamed,
2842
2845
) ) ;
@@ -2861,13 +2864,15 @@ fn clean_maybe_renamed_item<'tcx>(
2861
2864
} ) ,
2862
2865
ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. owner_id . def_id , cx) ,
2863
2866
ItemKind :: Macro ( _, macro_def, MacroKind :: Bang ) => MacroItem ( Macro {
2864
- source : display_macro_source ( cx, name, macro_def) ,
2867
+ source : display_macro_source ( cx, name. unwrap ( ) , macro_def) ,
2865
2868
macro_rules : macro_def. macro_rules ,
2866
2869
} ) ,
2867
- ItemKind :: Macro ( _, _, macro_kind) => clean_proc_macro ( item, & mut name, macro_kind, cx) ,
2870
+ ItemKind :: Macro ( _, _, macro_kind) => {
2871
+ clean_proc_macro ( item, name. as_mut ( ) . unwrap ( ) , macro_kind, cx)
2872
+ }
2868
2873
// proc macros can have a name set by attributes
2869
2874
ItemKind :: Fn { ref sig, generics, body : body_id, .. } => {
2870
- clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
2875
+ clean_fn_or_proc_macro ( item, sig, generics, body_id, name. as_mut ( ) . unwrap ( ) , cx)
2871
2876
}
2872
2877
ItemKind :: Trait ( _, _, _, generics, bounds, item_ids) => {
2873
2878
let items = item_ids
@@ -2883,7 +2888,7 @@ fn clean_maybe_renamed_item<'tcx>(
2883
2888
} ) )
2884
2889
}
2885
2890
ItemKind :: ExternCrate ( orig_name, _) => {
2886
- return clean_extern_crate ( item, name, orig_name, cx) ;
2891
+ return clean_extern_crate ( item, name. unwrap ( ) , orig_name, cx) ;
2887
2892
}
2888
2893
ItemKind :: Use ( path, kind) => {
2889
2894
return clean_use_statement ( item, name, path, kind, cx, & mut FxHashSet :: default ( ) ) ;
@@ -2895,7 +2900,7 @@ fn clean_maybe_renamed_item<'tcx>(
2895
2900
cx,
2896
2901
kind,
2897
2902
item. owner_id. def_id. to_def_id( ) ,
2898
- name,
2903
+ name. unwrap ( ) ,
2899
2904
import_id,
2900
2905
renamed,
2901
2906
) ]
@@ -3006,7 +3011,7 @@ fn clean_extern_crate<'tcx>(
3006
3011
3007
3012
fn clean_use_statement < ' tcx > (
3008
3013
import : & hir:: Item < ' tcx > ,
3009
- name : Symbol ,
3014
+ name : Option < Symbol > ,
3010
3015
path : & hir:: UsePath < ' tcx > ,
3011
3016
kind : hir:: UseKind ,
3012
3017
cx : & mut DocContext < ' tcx > ,
@@ -3023,7 +3028,7 @@ fn clean_use_statement<'tcx>(
3023
3028
3024
3029
fn clean_use_statement_inner < ' tcx > (
3025
3030
import : & hir:: Item < ' tcx > ,
3026
- name : Symbol ,
3031
+ name : Option < Symbol > ,
3027
3032
path : & hir:: Path < ' tcx > ,
3028
3033
kind : hir:: UseKind ,
3029
3034
cx : & mut DocContext < ' tcx > ,
@@ -3042,7 +3047,7 @@ fn clean_use_statement_inner<'tcx>(
3042
3047
let visibility = cx. tcx . visibility ( import. owner_id ) ;
3043
3048
let attrs = cx. tcx . hir_attrs ( import. hir_id ( ) ) ;
3044
3049
let inline_attr = hir_attr_lists ( attrs, sym:: doc) . get_word_attr ( sym:: inline) ;
3045
- let pub_underscore = visibility. is_public ( ) && name == kw:: Underscore ;
3050
+ let pub_underscore = visibility. is_public ( ) && name == Some ( kw:: Underscore ) ;
3046
3051
let current_mod = cx. tcx . parent_module_from_def_id ( import. owner_id . def_id ) ;
3047
3052
let import_def_id = import. owner_id . def_id ;
3048
3053
@@ -3108,6 +3113,7 @@ fn clean_use_statement_inner<'tcx>(
3108
3113
}
3109
3114
Import :: new_glob ( resolve_use_source ( cx, path) , true )
3110
3115
} else {
3116
+ let name = name. unwrap ( ) ;
3111
3117
if inline_attr. is_none ( )
3112
3118
&& let Res :: Def ( DefKind :: Mod , did) = path. res
3113
3119
&& !did. is_local ( )
0 commit comments