diff --git a/src/codegen/enums.rs b/src/codegen/enums.rs index 9351a3f98..f90203194 100644 --- a/src/codegen/enums.rs +++ b/src/codegen/enums.rs @@ -35,10 +35,7 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec) { let config = &env.config.objects[&enum_analysis.full_name]; let enum_ = enum_analysis.type_(&env.library); - if let Some(cfg) = version_condition_string(env, enum_.version, false, 0) { - mod_rs.push(cfg); - } - mod_rs.push(format!("pub use self::enums::{};", enum_.name)); + let condition = version_condition_string(env, enum_.version, false, 0); generate_enum(env, w, enum_, config)?; let functions = enum_analysis.functions(); @@ -59,7 +56,13 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec) { &enum_analysis.functions, &enum_analysis.specials, None, + condition.as_deref(), )?; + + if let Some(cfg) = condition { + mod_rs.push(cfg); + } + mod_rs.push(format!("pub use self::enums::{};", enum_.name)); } Ok(()) diff --git a/src/codegen/object.rs b/src/codegen/object.rs index bceff762c..25b399f15 100644 --- a/src/codegen/object.rs +++ b/src/codegen/object.rs @@ -82,6 +82,7 @@ pub fn generate( } else { None }, + None // TODO )?; if !analysis.builder_properties.is_empty() { diff --git a/src/codegen/record.rs b/src/codegen/record.rs index 509e5a663..5621b6b5d 100644 --- a/src/codegen/record.rs +++ b/src/codegen/record.rs @@ -114,6 +114,7 @@ pub fn generate(w: &mut dyn Write, env: &Env, analysis: &analysis::record::Info) &analysis.functions, &analysis.specials, None, + None, // TODO )?; if analysis.concurrency != library::Concurrency::None { diff --git a/src/codegen/trait_impls.rs b/src/codegen/trait_impls.rs index 7b017ed32..5b1539f79 100644 --- a/src/codegen/trait_impls.rs +++ b/src/codegen/trait_impls.rs @@ -10,6 +10,7 @@ pub fn generate( functions: &[Info], specials: &Infos, trait_name: Option<&str>, + condition: Option<&str>, ) -> Result<()> { for (type_, name) in specials.iter() { if let Some(info) = lookup(functions, name) { @@ -23,7 +24,7 @@ pub fn generate( Type::Equal => { generate_eq(w, type_name, info, trait_name)?; } - Type::ToString => generate_display(w, type_name, info, trait_name)?, + Type::ToString => generate_display(w, type_name, info, trait_name, condition)?, Type::Hash => generate_hash(w, type_name, info, trait_name)?, _ => {} } @@ -74,6 +75,7 @@ fn generate_display( type_name: &str, func: &Info, trait_name: Option<&str>, + condition: Option<&str>, ) -> Result<()> { use crate::analysis::out_parameters::Mode; @@ -91,10 +93,13 @@ fn generate_display( format!("f.write_str(&{})", call) }; + if let Some(condition) = condition { + writeln!(w, "{}", condition)?; + } + writeln!( w, - " -impl fmt::Display for {type_name} {{ + "impl fmt::Display for {type_name} {{ #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {{ {body}