Skip to content

Commit a90766e

Browse files
Correctly handle target_feature in rustdoc cfg
1 parent 7f80b97 commit a90766e

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
@@ -1251,35 +1251,20 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
12511251
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
12521252
// `doc(cfg())` overrides `cfg()`).
12531253
for attr in attrs {
1254-
let Some(ident) = attr.ident() else { continue };
1255-
match ident.name {
1256-
sym::cfg | sym::cfg_trace if !cfg_info.parent_is_doc_cfg => {
1257-
if let Some(attr) = single(attr.meta_item_list()?)
1258-
&& let Ok(new_cfg) = Cfg::parse(&attr)
1259-
{
1260-
cfg_info.current_cfg &= new_cfg;
1261-
}
1262-
}
1254+
if let hir::Attribute::Parsed(AttributeKind::TargetFeature(features, _)) = attr {
12631255
// treat #[target_feature(enable = "feat")] attributes as if they were
12641256
// #[doc(cfg(target_feature = "feat"))] attributes as well
1265-
sym::target_feature
1266-
if let Some(attrs) = attr.meta_item_list() =>
1267-
{
1268-
for attr in attrs {
1269-
if attr.has_name(sym::enable) && attr.value_str().is_some() {
1270-
// Clone `enable = "feat"`, change to `target_feature = "feat"`.
1271-
// Unwrap is safe because `value_str` succeeded above.
1272-
let mut meta = attr.meta_item().unwrap().clone();
1273-
meta.path =
1274-
ast::Path::from_ident(Ident::with_dummy_span(sym::target_feature));
1275-
1276-
if let Ok(feat_cfg) = Cfg::parse(&ast::MetaItemInner::MetaItem(meta)) {
1277-
cfg_info.current_cfg &= feat_cfg;
1278-
}
1279-
}
1280-
}
1257+
for (feature, _) in features {
1258+
cfg_info.current_cfg &= Cfg::Cfg(sym::target_feature, Some(*feature));
12811259
}
1282-
_ => {}
1260+
continue;
1261+
} else if !cfg_info.parent_is_doc_cfg
1262+
&& let Some(ident) = attr.ident()
1263+
&& matches!(ident.name, sym::cfg | sym::cfg_trace)
1264+
&& let Some(attr) = single(attr.meta_item_list()?)
1265+
&& let Ok(new_cfg) = Cfg::parse(&attr)
1266+
{
1267+
cfg_info.current_cfg &= new_cfg;
12831268
}
12841269
}
12851270

0 commit comments

Comments
 (0)