@@ -320,7 +320,7 @@ impl Item {
320
320
kind,
321
321
box ast_attrs. clean ( cx) ,
322
322
cx,
323
- ast_attrs. cfg ( cx. sess ( ) . diagnostic ( ) ) ,
323
+ ast_attrs. cfg ( cx. sess ( ) ) ,
324
324
)
325
325
}
326
326
@@ -332,7 +332,7 @@ impl Item {
332
332
cx : & mut DocContext < ' _ > ,
333
333
cfg : Option < Arc < Cfg > > ,
334
334
) -> Item {
335
- debug ! ( "name={:?}, def_id={:?}" , name, def_id) ;
335
+ trace ! ( "name={:?}, def_id={:?}" , name, def_id) ;
336
336
337
337
Item {
338
338
def_id,
@@ -681,7 +681,7 @@ crate trait AttributesExt {
681
681
682
682
fn other_attrs ( & self ) -> Vec < ast:: Attribute > ;
683
683
684
- fn cfg ( & self , diagnostic : & :: rustc_errors :: Handler ) -> Option < Arc < Cfg > > ;
684
+ fn cfg ( & self , sess : & Session ) -> Option < Arc < Cfg > > ;
685
685
}
686
686
687
687
impl AttributesExt for [ ast:: Attribute ] {
@@ -706,17 +706,28 @@ impl AttributesExt for [ast::Attribute] {
706
706
self . iter ( ) . filter ( |attr| attr. doc_str ( ) . is_none ( ) ) . cloned ( ) . collect ( )
707
707
}
708
708
709
- fn cfg ( & self , diagnostic : & :: rustc_errors :: Handler ) -> Option < Arc < Cfg > > {
709
+ fn cfg ( & self , sess : & Session ) -> Option < Arc < Cfg > > {
710
710
let mut cfg = Cfg :: True ;
711
711
712
712
for attr in self . iter ( ) {
713
+ // #[doc]
713
714
if attr. doc_str ( ) . is_none ( ) && attr. has_name ( sym:: doc) {
714
- if let Some ( mi) = attr. meta ( ) {
715
- if let Some ( cfg_mi) = Attributes :: extract_cfg ( & mi) {
716
- // Extracted #[doc(cfg(...))]
717
- match Cfg :: parse ( cfg_mi) {
718
- Ok ( new_cfg) => cfg &= new_cfg,
719
- Err ( e) => diagnostic. span_err ( e. span , e. msg ) ,
715
+ // #[doc(...)]
716
+ if let Some ( list) = attr. meta ( ) . as_ref ( ) . and_then ( |mi| mi. meta_item_list ( ) ) {
717
+ for item in list {
718
+ // #[doc(include)]
719
+ if !item. has_name ( sym:: cfg) {
720
+ continue ;
721
+ }
722
+ // #[doc(cfg(...))]
723
+ if let Some ( cfg_mi) = item
724
+ . meta_item ( )
725
+ . and_then ( |item| rustc_expand:: config:: parse_cfg ( & item, sess) )
726
+ {
727
+ match Cfg :: parse ( & cfg_mi) {
728
+ Ok ( new_cfg) => cfg &= new_cfg,
729
+ Err ( e) => sess. span_err ( e. span , e. msg ) ,
730
+ }
720
731
}
721
732
}
722
733
}
@@ -883,29 +894,6 @@ impl Attributes {
883
894
self . other_attrs . lists ( name)
884
895
}
885
896
886
- /// Extracts the content from an attribute `#[doc(cfg(content))]`.
887
- crate fn extract_cfg ( mi : & ast:: MetaItem ) -> Option < & ast:: MetaItem > {
888
- use rustc_ast:: NestedMetaItem :: MetaItem ;
889
-
890
- if let ast:: MetaItemKind :: List ( ref nmis) = mi. kind {
891
- if nmis. len ( ) == 1 {
892
- if let MetaItem ( ref cfg_mi) = nmis[ 0 ] {
893
- if cfg_mi. has_name ( sym:: cfg) {
894
- if let ast:: MetaItemKind :: List ( ref cfg_nmis) = cfg_mi. kind {
895
- if cfg_nmis. len ( ) == 1 {
896
- if let MetaItem ( ref content_mi) = cfg_nmis[ 0 ] {
897
- return Some ( content_mi) ;
898
- }
899
- }
900
- }
901
- }
902
- }
903
- }
904
- }
905
-
906
- None
907
- }
908
-
909
897
/// Reads a `MetaItem` from within an attribute, looks for whether it is a
910
898
/// `#[doc(include="file")]`, and returns the filename and contents of the file as loaded from
911
899
/// its expansion.
0 commit comments