@@ -1110,6 +1110,31 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
11101110 Some ( item)
11111111 }
11121112
1113+ fn check_changed_auto_active_status (
1114+ changed_auto_active_status : & mut Option < rustc_span:: Span > ,
1115+ attr : & ast:: MetaItem ,
1116+ cfg_info : & mut CfgInfo ,
1117+ tcx : TyCtxt < ' _ > ,
1118+ new_value : bool ,
1119+ ) -> bool {
1120+ if let Some ( first_change) = changed_auto_active_status {
1121+ if cfg_info. auto_cfg_active != new_value {
1122+ tcx. sess
1123+ . dcx ( )
1124+ . struct_span_err (
1125+ vec ! [ * first_change, attr. span] ,
1126+ "`auto_cfg` was disabled and enabled more than once on the same item" ,
1127+ )
1128+ . emit ( ) ;
1129+ return true ;
1130+ }
1131+ } else {
1132+ * changed_auto_active_status = Some ( attr. span ) ;
1133+ }
1134+ cfg_info. auto_cfg_active = new_value;
1135+ false
1136+ }
1137+
11131138 let mut new_show_attrs = FxHashMap :: default ( ) ;
11141139 let mut new_hide_attrs = FxHashMap :: default ( ) ;
11151140
@@ -1184,49 +1209,39 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
11841209 } ;
11851210 match & attr. kind {
11861211 MetaItemKind :: Word => {
1187- if let Some ( first_change) = changed_auto_active_status {
1188- if !cfg_info. auto_cfg_active {
1189- tcx. sess . dcx ( ) . struct_span_err (
1190- vec ! [ first_change, attr. span] ,
1191- "`auto_cfg` was disabled and enabled more than once on the same item" ,
1192- ) . emit ( ) ;
1193- return None ;
1194- }
1195- } else {
1196- changed_auto_active_status = Some ( attr. span ) ;
1212+ if check_changed_auto_active_status (
1213+ & mut changed_auto_active_status,
1214+ attr,
1215+ cfg_info,
1216+ tcx,
1217+ true ,
1218+ ) {
1219+ return None ;
11971220 }
1198- cfg_info. auto_cfg_active = true ;
11991221 }
12001222 MetaItemKind :: NameValue ( lit) => {
12011223 if let LitKind :: Bool ( value) = lit. kind {
1202- if let Some ( first_change) = changed_auto_active_status {
1203- if cfg_info. auto_cfg_active != value {
1204- tcx. sess . dcx ( ) . struct_span_err (
1205- vec ! [ first_change, attr. span] ,
1206- "`auto_cfg` was disabled and enabled more than once on the same item" ,
1207- ) . emit ( ) ;
1208- return None ;
1209- }
1210- } else {
1211- changed_auto_active_status = Some ( attr. span ) ;
1224+ if check_changed_auto_active_status (
1225+ & mut changed_auto_active_status,
1226+ attr,
1227+ cfg_info,
1228+ tcx,
1229+ value,
1230+ ) {
1231+ return None ;
12121232 }
1213- cfg_info. auto_cfg_active = value;
12141233 }
12151234 }
12161235 MetaItemKind :: List ( sub_attrs) => {
1217- if let Some ( first_change) = changed_auto_active_status {
1218- if !cfg_info. auto_cfg_active {
1219- tcx. sess . dcx ( ) . struct_span_err (
1220- vec ! [ first_change, attr. span] ,
1221- "`auto_cfg` was disabled and enabled more than once on the same item" ,
1222- ) . emit ( ) ;
1223- return None ;
1224- }
1225- } else {
1226- changed_auto_active_status = Some ( attr. span ) ;
1236+ if check_changed_auto_active_status (
1237+ & mut changed_auto_active_status,
1238+ attr,
1239+ cfg_info,
1240+ tcx,
1241+ true ,
1242+ ) {
1243+ return None ;
12271244 }
1228- // Whatever happens next, the feature is enabled again.
1229- cfg_info. auto_cfg_active = true ;
12301245 for sub_attr in sub_attrs. iter ( ) {
12311246 if let Some ( ident) = sub_attr. ident ( )
12321247 && ( ident. name == sym:: show || ident. name == sym:: hide)
0 commit comments