Skip to content

Commit 67e7367

Browse files
Correctly handle target_feature in rustdoc cfg
1 parent e165747 commit 67e7367

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
@@ -1237,35 +1237,20 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
12371237
// If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because
12381238
// `doc(cfg())` overrides `cfg()`).
12391239
for attr in attrs {
1240-
let Some(ident) = attr.ident() else { continue };
1241-
match ident.name {
1242-
sym::cfg | sym::cfg_trace if !cfg_info.parent_is_doc_cfg => {
1243-
if let Some(attr) = single(attr.meta_item_list()?)
1244-
&& let Ok(new_cfg) = Cfg::parse(&attr)
1245-
{
1246-
cfg_info.current_cfg &= new_cfg;
1247-
}
1248-
}
1240+
if let hir::Attribute::Parsed(AttributeKind::TargetFeature(features, _)) = attr {
12491241
// treat #[target_feature(enable = "feat")] attributes as if they were
12501242
// #[doc(cfg(target_feature = "feat"))] attributes as well
1251-
sym::target_feature
1252-
if let Some(attrs) = attr.meta_item_list() =>
1253-
{
1254-
for attr in attrs {
1255-
if attr.has_name(sym::enable) && attr.value_str().is_some() {
1256-
// Clone `enable = "feat"`, change to `target_feature = "feat"`.
1257-
// Unwrap is safe because `value_str` succeeded above.
1258-
let mut meta = attr.meta_item().unwrap().clone();
1259-
meta.path =
1260-
ast::Path::from_ident(Ident::with_dummy_span(sym::target_feature));
1261-
1262-
if let Ok(feat_cfg) = Cfg::parse(&ast::MetaItemInner::MetaItem(meta)) {
1263-
cfg_info.current_cfg &= feat_cfg;
1264-
}
1265-
}
1266-
}
1243+
for (feature, _) in features {
1244+
cfg_info.current_cfg &= Cfg::Cfg(sym::target_feature, Some(*feature));
12671245
}
1268-
_ => {}
1246+
continue;
1247+
} else if !cfg_info.parent_is_doc_cfg
1248+
&& let Some(ident) = attr.ident()
1249+
&& matches!(ident.name, sym::cfg | sym::cfg_trace)
1250+
&& let Some(attr) = single(attr.meta_item_list()?)
1251+
&& let Ok(new_cfg) = Cfg::parse(&attr)
1252+
{
1253+
cfg_info.current_cfg &= new_cfg;
12691254
}
12701255
}
12711256

0 commit comments

Comments
 (0)