@@ -10,7 +10,7 @@ use std::collections::hash_map::Entry;
1010use std:: slice;
1111
1212use rustc_abi:: { Align , ExternAbi , Size } ;
13- use rustc_ast:: { AttrStyle , LitKind , MetaItemInner , MetaItemKind , ast} ;
13+ use rustc_ast:: { AttrStyle , LitKind , MetaItem , MetaItemInner , MetaItemKind , ast} ;
1414use rustc_attr_parsing:: { AttributeParser , Late } ;
1515use rustc_data_structures:: fx:: FxHashMap ;
1616use rustc_errors:: { Applicability , DiagCtxtHandle , IntoDiagArg , MultiSpan , StashKey } ;
@@ -1160,16 +1160,74 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11601160 }
11611161 }
11621162
1163- /// Check that the `#![doc(cfg_hide(...))]` attribute only contains a list of attributes.
1164- ///
1165- fn check_doc_cfg_hide ( & self , meta : & MetaItemInner , hir_id : HirId ) {
1166- if meta. meta_item_list ( ) . is_none ( ) {
1167- self . tcx . emit_node_span_lint (
1168- INVALID_DOC_ATTRIBUTES ,
1169- hir_id,
1170- meta. span ( ) ,
1171- errors:: DocCfgHideTakesList ,
1172- ) ;
1163+ /// Check that the `#![doc(auto_cfg(..))]` attribute has expected input.
1164+ fn check_doc_auto_cfg ( & self , meta : & MetaItem , hir_id : HirId ) {
1165+ match & meta. kind {
1166+ MetaItemKind :: Word => { }
1167+ MetaItemKind :: NameValue ( lit) => {
1168+ if !matches ! ( lit. kind, LitKind :: Bool ( _) ) {
1169+ self . tcx . emit_node_span_lint (
1170+ INVALID_DOC_ATTRIBUTES ,
1171+ hir_id,
1172+ meta. span ,
1173+ errors:: DocAutoCfgWrongLiteral ,
1174+ ) ;
1175+ }
1176+ }
1177+ MetaItemKind :: List ( list) => {
1178+ for item in list {
1179+ let Some ( attr_name) = item. name ( ) else {
1180+ self . tcx . emit_node_span_lint (
1181+ INVALID_DOC_ATTRIBUTES ,
1182+ hir_id,
1183+ meta. span ,
1184+ errors:: DocAutoCfgExpectsHideOrShow ,
1185+ ) ;
1186+ continue ;
1187+ } ;
1188+ if attr_name != sym:: hide && attr_name != sym:: show {
1189+ self . tcx . emit_node_span_lint (
1190+ INVALID_DOC_ATTRIBUTES ,
1191+ hir_id,
1192+ meta. span ,
1193+ errors:: DocAutoCfgExpectsHideOrShow ,
1194+ ) ;
1195+ } else if let Some ( list) = item. meta_item_list ( ) {
1196+ for item in list {
1197+ if item. meta_item_list ( ) . is_some ( ) {
1198+ self . tcx . emit_node_span_lint (
1199+ INVALID_DOC_ATTRIBUTES ,
1200+ hir_id,
1201+ item. span ( ) ,
1202+ errors:: DocAutoCfgHideShowUnexpectedItem {
1203+ attr_name : attr_name. as_str ( ) ,
1204+ } ,
1205+ ) ;
1206+ } else if match item {
1207+ MetaItemInner :: Lit ( _) => true ,
1208+ // We already checked above that it's not a list.
1209+ MetaItemInner :: MetaItem ( meta) => meta. path . segments . len ( ) != 1 ,
1210+ } {
1211+ self . tcx . emit_node_span_lint (
1212+ INVALID_DOC_ATTRIBUTES ,
1213+ hir_id,
1214+ item. span ( ) ,
1215+ errors:: DocAutoCfgHideShowUnexpectedItem {
1216+ attr_name : attr_name. as_str ( ) ,
1217+ } ,
1218+ ) ;
1219+ }
1220+ }
1221+ } else {
1222+ self . tcx . emit_node_span_lint (
1223+ INVALID_DOC_ATTRIBUTES ,
1224+ hir_id,
1225+ meta. span ,
1226+ errors:: DocAutoCfgHideShowExpectsList { attr_name : attr_name. as_str ( ) } ,
1227+ ) ;
1228+ }
1229+ }
1230+ }
11731231 }
11741232 }
11751233
@@ -1245,10 +1303,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12451303 self . check_attr_crate_level ( attr, style, meta, hir_id) ;
12461304 }
12471305
1248- Some ( sym:: cfg_hide) => {
1249- if self . check_attr_crate_level ( attr, style, meta, hir_id) {
1250- self . check_doc_cfg_hide ( meta, hir_id) ;
1251- }
1306+ Some ( sym:: auto_cfg) => {
1307+ self . check_doc_auto_cfg ( i_meta, hir_id) ;
12521308 }
12531309
12541310 Some ( sym:: inline | sym:: no_inline) => {
0 commit comments