@@ -320,7 +320,7 @@ impl Item {
320320 kind,
321321 box ast_attrs. clean ( cx) ,
322322 cx,
323- ast_attrs. cfg ( cx. sess ( ) . diagnostic ( ) ) ,
323+ ast_attrs. cfg ( cx. sess ( ) ) ,
324324 )
325325 }
326326
@@ -332,7 +332,7 @@ impl Item {
332332 cx : & mut DocContext < ' _ > ,
333333 cfg : Option < Arc < Cfg > > ,
334334 ) -> Item {
335- debug ! ( "name={:?}, def_id={:?}" , name, def_id) ;
335+ trace ! ( "name={:?}, def_id={:?}" , name, def_id) ;
336336
337337 Item {
338338 def_id,
@@ -681,7 +681,7 @@ crate trait AttributesExt {
681681
682682 fn other_attrs ( & self ) -> Vec < ast:: Attribute > ;
683683
684- fn cfg ( & self , diagnostic : & :: rustc_errors :: Handler ) -> Option < Arc < Cfg > > ;
684+ fn cfg ( & self , sess : & Session ) -> Option < Arc < Cfg > > ;
685685}
686686
687687impl AttributesExt for [ ast:: Attribute ] {
@@ -706,17 +706,28 @@ impl AttributesExt for [ast::Attribute] {
706706 self . iter ( ) . filter ( |attr| attr. doc_str ( ) . is_none ( ) ) . cloned ( ) . collect ( )
707707 }
708708
709- fn cfg ( & self , diagnostic : & :: rustc_errors :: Handler ) -> Option < Arc < Cfg > > {
709+ fn cfg ( & self , sess : & Session ) -> Option < Arc < Cfg > > {
710710 let mut cfg = Cfg :: True ;
711711
712712 for attr in self . iter ( ) {
713+ // #[doc]
713714 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+ }
720731 }
721732 }
722733 }
@@ -883,29 +894,6 @@ impl Attributes {
883894 self . other_attrs . lists ( name)
884895 }
885896
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-
909897 /// Reads a `MetaItem` from within an attribute, looks for whether it is a
910898 /// `#[doc(include="file")]`, and returns the filename and contents of the file as loaded from
911899 /// its expansion.
0 commit comments