@@ -119,14 +119,25 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
119
119
} ) ;
120
120
121
121
let kind = ModuleItem ( Module { items, span } ) ;
122
- let def_id = doc. def_id . to_def_id ( ) ;
122
+ generate_item_with_correct_attrs ( cx, kind, doc. def_id , doc. name , doc. import_id , doc. renamed )
123
+ }
124
+
125
+ fn generate_item_with_correct_attrs (
126
+ cx : & mut DocContext < ' _ > ,
127
+ kind : ItemKind ,
128
+ local_def_id : LocalDefId ,
129
+ name : Symbol ,
130
+ import_id : Option < LocalDefId > ,
131
+ renamed : Option < Symbol > ,
132
+ ) -> Item {
133
+ let def_id = local_def_id. to_def_id ( ) ;
123
134
let target_attrs = inline:: load_attrs ( cx, def_id) ;
124
- let attrs = if let Some ( import_id) = doc . import_id {
135
+ let attrs = if let Some ( import_id) = import_id {
125
136
let is_inline = inline:: load_attrs ( cx, import_id. to_def_id ( ) )
126
137
. lists ( sym:: doc)
127
138
. get_word_attr ( sym:: inline)
128
139
. is_some ( ) ;
129
- let mut attrs = get_all_import_attributes ( cx, import_id, doc . def_id , is_inline) ;
140
+ let mut attrs = get_all_import_attributes ( cx, import_id, local_def_id , is_inline) ;
130
141
add_without_unwanted_attributes ( & mut attrs, target_attrs, is_inline, None ) ;
131
142
attrs
132
143
} else {
@@ -137,9 +148,9 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
137
148
let cfg = attrs. cfg ( cx. tcx , & cx. cache . hidden_cfg ) ;
138
149
let attrs = Attributes :: from_ast_iter ( attrs. iter ( ) . map ( |( attr, did) | ( & * * attr, * did) ) , false ) ;
139
150
140
- let name = doc . renamed . or_else ( || Some ( doc . name ) ) ;
151
+ let name = renamed. or ( Some ( name) ) ;
141
152
let mut item = Item :: from_def_id_and_attrs_and_parts ( def_id, name, kind, Box :: new ( attrs) , cfg) ;
142
- item. inline_stmt_id = doc . import_id . map ( |local| local. to_def_id ( ) ) ;
153
+ item. inline_stmt_id = import_id. map ( |local| local. to_def_id ( ) ) ;
143
154
item
144
155
}
145
156
@@ -2309,29 +2320,14 @@ fn clean_maybe_renamed_item<'tcx>(
2309
2320
_ => unreachable ! ( "not yet converted" ) ,
2310
2321
} ;
2311
2322
2312
- let target_attrs = inline:: load_attrs ( cx, def_id) ;
2313
- let attrs = if let Some ( import_id) = import_id {
2314
- let is_inline = inline:: load_attrs ( cx, import_id. to_def_id ( ) )
2315
- . lists ( sym:: doc)
2316
- . get_word_attr ( sym:: inline)
2317
- . is_some ( ) ;
2318
- let mut attrs =
2319
- get_all_import_attributes ( cx, import_id, item. owner_id . def_id , is_inline) ;
2320
- add_without_unwanted_attributes ( & mut attrs, target_attrs, is_inline, None ) ;
2321
- attrs
2322
- } else {
2323
- // We only keep the item's attributes.
2324
- target_attrs. iter ( ) . map ( |attr| ( Cow :: Borrowed ( attr) , None ) ) . collect ( )
2325
- } ;
2326
-
2327
- let cfg = attrs. cfg ( cx. tcx , & cx. cache . hidden_cfg ) ;
2328
- let attrs =
2329
- Attributes :: from_ast_iter ( attrs. iter ( ) . map ( |( attr, did) | ( & * * attr, * did) ) , false ) ;
2330
-
2331
- let mut item =
2332
- Item :: from_def_id_and_attrs_and_parts ( def_id, Some ( name) , kind, Box :: new ( attrs) , cfg) ;
2333
- item. inline_stmt_id = import_id. map ( |local| local. to_def_id ( ) ) ;
2334
- vec ! [ item]
2323
+ vec ! [ generate_item_with_correct_attrs(
2324
+ cx,
2325
+ kind,
2326
+ item. owner_id. def_id,
2327
+ name,
2328
+ import_id,
2329
+ renamed,
2330
+ ) ]
2335
2331
} )
2336
2332
}
2337
2333
0 commit comments