1
1
//! Support for inlining external documentation into the current AST.
2
2
3
3
use std:: iter:: once;
4
+ use std:: sync:: Arc ;
4
5
5
6
use rustc_ast as ast;
6
7
use rustc_data_structures:: fx:: FxHashSet ;
@@ -14,7 +15,7 @@ use rustc_span::hygiene::MacroKind;
14
15
use rustc_span:: symbol:: { kw, sym, Symbol } ;
15
16
use rustc_span:: Span ;
16
17
17
- use crate :: clean:: { self , Attributes , GetDefId , ToSource } ;
18
+ use crate :: clean:: { self , Attributes , AttributesExt , GetDefId , ToSource } ;
18
19
use crate :: core:: DocContext ;
19
20
use crate :: formats:: item_type:: ItemType ;
20
21
@@ -119,12 +120,16 @@ crate fn try_inline(
119
120
_ => return None ,
120
121
} ;
121
122
122
- let target_attrs = load_attrs ( cx, did) ;
123
- let attrs = box merge_attrs ( cx, Some ( parent_module) , target_attrs, attrs_clone) ;
124
-
123
+ let ( attrs, cfg) = merge_attrs ( cx, Some ( parent_module) , load_attrs ( cx, did) , attrs_clone) ;
125
124
cx. inlined . insert ( did) ;
126
- let what_rustc_thinks = clean:: Item :: from_def_id_and_parts ( did, Some ( name) , kind, cx) ;
127
- ret. push ( clean:: Item { attrs, ..what_rustc_thinks } ) ;
125
+ ret. push ( clean:: Item :: from_def_id_and_attrs_and_parts (
126
+ did,
127
+ Some ( name) ,
128
+ kind,
129
+ box attrs,
130
+ cx,
131
+ cfg,
132
+ ) ) ;
128
133
Some ( ret)
129
134
}
130
135
@@ -288,22 +293,24 @@ fn merge_attrs(
288
293
parent_module : Option < DefId > ,
289
294
old_attrs : Attrs < ' _ > ,
290
295
new_attrs : Option < Attrs < ' _ > > ,
291
- ) -> clean:: Attributes {
296
+ ) -> ( clean:: Attributes , Option < Arc < clean :: cfg :: Cfg > > ) {
292
297
// NOTE: If we have additional attributes (from a re-export),
293
298
// always insert them first. This ensure that re-export
294
299
// doc comments show up before the original doc comments
295
300
// when we render them.
296
301
if let Some ( inner) = new_attrs {
297
- if let Some ( new_id) = parent_module {
298
- let diag = cx. sess ( ) . diagnostic ( ) ;
299
- Attributes :: from_ast ( diag, old_attrs, Some ( ( inner, new_id) ) )
300
- } else {
301
- let mut both = inner. to_vec ( ) ;
302
- both. extend_from_slice ( old_attrs) ;
303
- both. clean ( cx)
304
- }
302
+ let mut both = inner. to_vec ( ) ;
303
+ both. extend_from_slice ( old_attrs) ;
304
+ (
305
+ if let Some ( new_id) = parent_module {
306
+ Attributes :: from_ast ( old_attrs, Some ( ( inner, new_id) ) )
307
+ } else {
308
+ Attributes :: from_ast ( & both, None )
309
+ } ,
310
+ both. cfg ( cx. sess ( ) . diagnostic ( ) ) ,
311
+ )
305
312
} else {
306
- old_attrs. clean ( cx)
313
+ ( old_attrs. clean ( cx) , old_attrs . cfg ( cx . sess ( ) . diagnostic ( ) ) )
307
314
}
308
315
}
309
316
@@ -414,8 +421,8 @@ crate fn build_impl(
414
421
415
422
debug ! ( "build_impl: impl {:?} for {:?}" , trait_. def_id( ) , for_. def_id( ) ) ;
416
423
417
- let attrs = box merge_attrs ( cx, parent_module. into ( ) , load_attrs ( cx, did) , attrs) ;
418
- debug ! ( "merged_attrs={:?}" , attrs ) ;
424
+ let ( merged_attrs , cfg ) = merge_attrs ( cx, parent_module. into ( ) , load_attrs ( cx, did) , attrs) ;
425
+ debug ! ( "merged_attrs={:?}" , merged_attrs ) ;
419
426
420
427
ret. push ( clean:: Item :: from_def_id_and_attrs_and_parts (
421
428
did,
@@ -432,8 +439,9 @@ crate fn build_impl(
432
439
synthetic : false ,
433
440
blanket_impl : None ,
434
441
} ) ,
435
- attrs ,
442
+ box merged_attrs ,
436
443
cx,
444
+ cfg,
437
445
) ) ;
438
446
}
439
447
@@ -479,6 +487,7 @@ fn build_module(
479
487
} ,
480
488
true ,
481
489
) ) ,
490
+ cfg : None ,
482
491
} ) ;
483
492
} else if let Some ( i) = try_inline ( cx, did, item. res , item. ident . name , None , visited) {
484
493
items. extend ( i)
0 commit comments