@@ -117,16 +117,22 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
117117 hir:: ItemKind :: Use ( path, kind) => {
118118 let hir:: UsePath { segments, span, .. } = * path;
119119 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+ )
121128 }
122129 _ => unreachable ! ( ) ,
123130 }
124131 } ) ) ;
125132 items. extend ( doc. items . values ( ) . flat_map ( |( item, renamed, _) | {
126133 // Now we actually lower the imports, skipping everything else.
127134 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)
130136 } else {
131137 // skip everything else
132138 Vec :: new ( )
@@ -1072,10 +1078,10 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
10721078 ..
10731079 } = param
10741080 {
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+ ) ;
10791085 } else {
10801086 panic ! ( "unexpected non const in position {pos}" ) ;
10811087 }
@@ -1132,9 +1138,9 @@ fn clean_args_from_types_and_names<'tcx>(
11321138 // If at least one argument has a name, use `_` as the name of unnamed
11331139 // arguments. Otherwise omit argument names.
11341140 let default_name = if idents. iter ( ) . any ( |ident| nonempty_name ( ident) . is_some ( ) ) {
1135- kw:: Underscore
1141+ Some ( kw:: Underscore )
11361142 } else {
1137- kw :: Empty
1143+ None
11381144 } ;
11391145
11401146 Arguments {
@@ -1143,7 +1149,7 @@ fn clean_args_from_types_and_names<'tcx>(
11431149 . enumerate ( )
11441150 . map ( |( i, ty) | Argument {
11451151 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) ,
11471153 is_const : false ,
11481154 } )
11491155 . collect ( ) ,
@@ -1162,7 +1168,7 @@ fn clean_args_from_types_and_body_id<'tcx>(
11621168 . iter ( )
11631169 . zip ( body. params )
11641170 . map ( |( ty, param) | Argument {
1165- name : name_from_pat ( param. pat ) ,
1171+ name : Some ( name_from_pat ( param. pat ) ) ,
11661172 type_ : clean_ty ( ty, cx) ,
11671173 is_const : false ,
11681174 } )
@@ -1218,11 +1224,11 @@ fn clean_poly_fn_sig<'tcx>(
12181224 . iter ( )
12191225 . map ( |t| Argument {
12201226 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 ( ) {
12221228 ident. name
12231229 } else {
12241230 kw:: Underscore
1225- } ,
1231+ } ) ,
12261232 is_const : false ,
12271233 } )
12281234 . collect ( ) ,
@@ -2792,10 +2798,7 @@ fn clean_maybe_renamed_item<'tcx>(
27922798 use hir:: ItemKind ;
27932799
27942800 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 ( ) ) } ;
27992802
28002803 cx. with_param_env ( def_id, |cx| {
28012804 let kind = match item. kind {
@@ -2836,7 +2839,7 @@ fn clean_maybe_renamed_item<'tcx>(
28362839 item_type : Some ( type_) ,
28372840 } ) ) ,
28382841 item. owner_id . def_id . to_def_id ( ) ,
2839- name,
2842+ name. unwrap ( ) ,
28402843 import_id,
28412844 renamed,
28422845 ) ) ;
@@ -2861,13 +2864,15 @@ fn clean_maybe_renamed_item<'tcx>(
28612864 } ) ,
28622865 ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. owner_id . def_id , cx) ,
28632866 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) ,
28652868 macro_rules : macro_def. macro_rules ,
28662869 } ) ,
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+ }
28682873 // proc macros can have a name set by attributes
28692874 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)
28712876 }
28722877 ItemKind :: Trait ( _, _, _, generics, bounds, item_ids) => {
28732878 let items = item_ids
@@ -2883,7 +2888,7 @@ fn clean_maybe_renamed_item<'tcx>(
28832888 } ) )
28842889 }
28852890 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) ;
28872892 }
28882893 ItemKind :: Use ( path, kind) => {
28892894 return clean_use_statement ( item, name, path, kind, cx, & mut FxHashSet :: default ( ) ) ;
@@ -2895,7 +2900,7 @@ fn clean_maybe_renamed_item<'tcx>(
28952900 cx,
28962901 kind,
28972902 item. owner_id. def_id. to_def_id( ) ,
2898- name,
2903+ name. unwrap ( ) ,
28992904 import_id,
29002905 renamed,
29012906 ) ]
@@ -3006,7 +3011,7 @@ fn clean_extern_crate<'tcx>(
30063011
30073012fn clean_use_statement < ' tcx > (
30083013 import : & hir:: Item < ' tcx > ,
3009- name : Symbol ,
3014+ name : Option < Symbol > ,
30103015 path : & hir:: UsePath < ' tcx > ,
30113016 kind : hir:: UseKind ,
30123017 cx : & mut DocContext < ' tcx > ,
@@ -3023,7 +3028,7 @@ fn clean_use_statement<'tcx>(
30233028
30243029fn clean_use_statement_inner < ' tcx > (
30253030 import : & hir:: Item < ' tcx > ,
3026- name : Symbol ,
3031+ name : Option < Symbol > ,
30273032 path : & hir:: Path < ' tcx > ,
30283033 kind : hir:: UseKind ,
30293034 cx : & mut DocContext < ' tcx > ,
@@ -3042,7 +3047,7 @@ fn clean_use_statement_inner<'tcx>(
30423047 let visibility = cx. tcx . visibility ( import. owner_id ) ;
30433048 let attrs = cx. tcx . hir_attrs ( import. hir_id ( ) ) ;
30443049 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 ) ;
30463051 let current_mod = cx. tcx . parent_module_from_def_id ( import. owner_id . def_id ) ;
30473052 let import_def_id = import. owner_id . def_id ;
30483053
@@ -3108,6 +3113,7 @@ fn clean_use_statement_inner<'tcx>(
31083113 }
31093114 Import :: new_glob ( resolve_use_source ( cx, path) , true )
31103115 } else {
3116+ let name = name. unwrap ( ) ;
31113117 if inline_attr. is_none ( )
31123118 && let Res :: Def ( DefKind :: Mod , did) = path. res
31133119 && !did. is_local ( )
0 commit comments