Skip to content

Commit 13aa746

Browse files
Correctly handle target_feature in rustdoc cfg
1 parent c3facd4 commit 13aa746

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

src/librustdoc/clean/types.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,35 +1265,20 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
12651265
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
12661266
// `doc(cfg())` overrides `cfg()`).
12671267
for attr in attrs {
1268-
let Some(ident) = attr.ident() else { continue };
1269-
match ident.name {
1270-
sym::cfg | sym::cfg_trace if !cfg_info.parent_is_doc_cfg => {
1271-
if let Some(attr) = single(attr.meta_item_list()?)
1272-
&& let Ok(new_cfg) = Cfg::parse(&attr)
1273-
{
1274-
cfg_info.current_cfg &= new_cfg;
1275-
}
1276-
}
1268+
if let hir::Attribute::Parsed(AttributeKind::TargetFeature { features, .. }) = attr {
12771269
// treat #[target_feature(enable = "feat")] attributes as if they were
12781270
// #[doc(cfg(target_feature = "feat"))] attributes as well
1279-
sym::target_feature
1280-
if let Some(attrs) = attr.meta_item_list() =>
1281-
{
1282-
for attr in attrs {
1283-
if attr.has_name(sym::enable) && attr.value_str().is_some() {
1284-
// Clone `enable = "feat"`, change to `target_feature = "feat"`.
1285-
// Unwrap is safe because `value_str` succeeded above.
1286-
let mut meta = attr.meta_item().unwrap().clone();
1287-
meta.path =
1288-
ast::Path::from_ident(Ident::with_dummy_span(sym::target_feature));
1289-
1290-
if let Ok(feat_cfg) = Cfg::parse(&ast::MetaItemInner::MetaItem(meta)) {
1291-
cfg_info.current_cfg &= feat_cfg;
1292-
}
1293-
}
1294-
}
1271+
for (feature, _) in features {
1272+
cfg_info.current_cfg &= Cfg::Cfg(sym::target_feature, Some(*feature));
12951273
}
1296-
_ => {}
1274+
continue;
1275+
} else if !cfg_info.parent_is_doc_cfg
1276+
&& let Some(ident) = attr.ident()
1277+
&& matches!(ident.name, sym::cfg | sym::cfg_trace)
1278+
&& let Some(attr) = single(attr.meta_item_list()?)
1279+
&& let Ok(new_cfg) = Cfg::parse(&attr)
1280+
{
1281+
cfg_info.current_cfg &= new_cfg;
12971282
}
12981283
}
12991284

0 commit comments

Comments
 (0)