Skip to content

Commit d15451b

Browse files
fix(document-metrics): Add support for all in cfg (#4708)
1 parent 5b5e2b4 commit d15451b

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

tools/document-metrics/src/main.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,26 @@ fn add_doc_line(docs: &mut String, nv: &syn::MetaNameValue) {
6464
/// Adds the name of the feature if the given attribute is a `cfg(feature)` attribute.
6565
fn add_feature(features: &mut Vec<String>, l: &syn::MetaList) -> Result<()> {
6666
if l.path.is_ident("cfg") {
67-
l.parse_nested_meta(|meta| {
68-
if meta.path.is_ident("feature") {
69-
let s = meta.value()?.parse::<LitStr>()?;
70-
features.push(s.value());
71-
} else if let Some(ident) = meta.path.get_ident() {
72-
features.push(ident.to_string());
73-
} else if !meta.input.peek(syn::Token![,]) {
74-
// Ignore everything else.
75-
let _ = meta.value()?.parse::<Lit>()?;
76-
}
77-
Ok(())
78-
})?;
67+
l.parse_nested_meta(|meta| process_meta_item(features, &meta))?;
7968
}
69+
Ok(())
70+
}
8071

72+
/// Recursively processes a meta item and its nested items.
73+
fn process_meta_item(
74+
features: &mut Vec<String>,
75+
meta: &syn::meta::ParseNestedMeta,
76+
) -> syn::Result<()> {
77+
if meta.path.is_ident("feature") {
78+
let s = meta.value()?.parse::<LitStr>()?;
79+
features.push(s.value());
80+
} else if meta.path.is_ident("all") {
81+
meta.parse_nested_meta(|nested_meta| process_meta_item(features, &nested_meta))?;
82+
} else if let Some(ident) = meta.path.get_ident() {
83+
features.push(ident.to_string());
84+
} else if !meta.input.peek(syn::Token![,]) {
85+
let _ = meta.value()?.parse::<Lit>()?;
86+
}
8187
Ok(())
8288
}
8389

@@ -303,6 +309,9 @@ mod tests {
303309
/// Another metric we test.
304310
#[cfg(cfg_flag)]
305311
ConditionalCompileSet,
312+
/// Yet another metric we test.
313+
#[cfg(all(cfg_flag, feature = "conditional"))]
314+
MultiConditionalCompileSet,
306315
}
307316
308317
impl SetMetric for TestSets {
@@ -313,6 +322,8 @@ mod tests {
313322
Self::ConditionalSet => "test.conditional",
314323
#[cfg(cfg_flag)]
315324
Self::ConditionalCompileSet => "test.conditional_compile",
325+
#[cfg(all(cfg_flag, feature = "conditional"))]
326+
Self::MultiConditionalCompileSet => "test.multi_conditional_compile"
316327
}
317328
}
318329
}
@@ -337,6 +348,15 @@ mod tests {
337348
"cfg_flag",
338349
],
339350
},
351+
Metric {
352+
ty: Set,
353+
name: "test.multi_conditional_compile",
354+
description: "Yet another metric we test.",
355+
features: [
356+
"cfg_flag",
357+
"conditional",
358+
],
359+
},
340360
Metric {
341361
ty: Set,
342362
name: "test.unique",

0 commit comments

Comments
 (0)