Skip to content

Commit f7754a0

Browse files
Correctly handle target_feature in rustdoc cfg
1 parent 1c15732 commit f7754a0

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/librustdoc/clean/types.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use itertools::Either;
88
use rustc_abi::{ExternAbi, VariantIdx};
99
use rustc_ast::ast::{LitKind, MetaItemInner, MetaItemKind};
1010
use rustc_attr_data_structures::{
11-
AttributeKind, ConstStability, Deprecation, Stability, StableSince, find_attr,
11+
AttributeKind, ConstStability, Deprecation, Stability, StableSince,
1212
};
1313
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
1414
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -1236,35 +1236,20 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
12361236
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
12371237
// `doc(cfg())` overrides `cfg()`).
12381238
for attr in attrs {
1239-
let Some(ident) = attr.ident() else { continue };
1240-
match ident.name {
1241-
sym::cfg | sym::cfg_trace if !cfg_info.parent_is_doc_cfg => {
1242-
if let Some(attr) = single(attr.meta_item_list()?)
1243-
&& let Ok(new_cfg) = Cfg::parse(&attr)
1244-
{
1245-
cfg_info.current_cfg &= new_cfg;
1246-
}
1247-
}
1239+
if let hir::Attribute::Parsed(AttributeKind::TargetFeature(features, _)) = attr {
12481240
// treat #[target_feature(enable = "feat")] attributes as if they were
12491241
// #[doc(cfg(target_feature = "feat"))] attributes as well
1250-
sym::target_feature
1251-
if let Some(attrs) = attr.meta_item_list() =>
1252-
{
1253-
for attr in attrs {
1254-
if attr.has_name(sym::enable) && attr.value_str().is_some() {
1255-
// Clone `enable = "feat"`, change to `target_feature = "feat"`.
1256-
// Unwrap is safe because `value_str` succeeded above.
1257-
let mut meta = attr.meta_item().unwrap().clone();
1258-
meta.path =
1259-
ast::Path::from_ident(Ident::with_dummy_span(sym::target_feature));
1260-
1261-
if let Ok(feat_cfg) = Cfg::parse(&ast::MetaItemInner::MetaItem(meta)) {
1262-
cfg_info.current_cfg &= feat_cfg;
1263-
}
1264-
}
1265-
}
1242+
for (feature, _) in features {
1243+
cfg_info.current_cfg &= Cfg::Cfg(sym::target_feature, Some(*feature));
12661244
}
1267-
_ => {}
1245+
continue;
1246+
} else if !cfg_info.parent_is_doc_cfg
1247+
&& let Some(ident) = attr.ident()
1248+
&& matches!(ident.name, sym::cfg | sym::cfg_trace)
1249+
&& let Some(attr) = single(attr.meta_item_list()?)
1250+
&& let Ok(new_cfg) = Cfg::parse(&attr)
1251+
{
1252+
cfg_info.current_cfg &= new_cfg;
12681253
}
12691254
}
12701255

0 commit comments

Comments
 (0)