codegen/general: Simplify version by reusing cfg_condition_string
@@ -504,14 +504,7 @@ pub fn version_condition_string(
) -> Option<String> {
match version {
Some(v) if v > env.config.min_cfg_version => {
- let comment = if commented { "//" } else { "" };
- Some(format!(
- "{0}{1}#[cfg(any({2}, feature = \"dox\"))]\n\
- {0}{1}#[cfg_attr(feature = \"dox\", doc(cfg({2})))]",
- tabs(indent),
- comment,
- v.to_cfg()
- ))
+ cfg_condition_string(&Some(v.to_cfg()), commented, indent)
}
_ => None,
}
@@ -523,15 +516,9 @@ pub fn not_version_condition(
commented: bool,
indent: usize,
) -> Result<()> {
- if let Some(v) = version {
- let comment = if commented { "//" } else { "" };
- let s = format!(
- "{0}{1}#[cfg(any(not({2}), feature = \"dox\"))]\n\
- {0}{1}#[cfg_attr(feature = \"dox\", doc(cfg(not({2}))))]",
- tabs(indent),
- comment,
- v.to_cfg()
- );
+ if let Some(s) = version.and_then(|v| {
+ cfg_condition_string(&Some(format!("not({})", v.to_cfg())), commented, indent)
+ }) {
writeln!(w, "{}", s)?;
}
Ok(())
