diff --git a/src/ast.rs b/src/ast.rs index c5409298..ed161df0 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -72,7 +72,7 @@ pub struct ScriptFnDef { /// Not available under `no_function`. #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - pub comments: StaticVec>, + pub comments: Option]>>, } impl fmt::Display for ScriptFnDef { @@ -151,7 +151,10 @@ impl<'a> From<&'a ScriptFnDef> for ScriptFnMetadata<'a> { Self { #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - comments: value.comments.iter().map(Box::as_ref).collect(), + comments: value + .comments + .as_ref() + .map_or_else(|| Vec::new(), |v| v.iter().map(Box::as_ref).collect()), access: value.access, name: &value.name, params: value.params.iter().map(|s| s.as_str()).collect(), diff --git a/src/optimize.rs b/src/optimize.rs index 12699422..32d8021b 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -1165,7 +1165,7 @@ pub fn optimize_into_ast( mods: crate::engine::Imports::new(), #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - comments: StaticVec::new(), + comments: None, }) .for_each(|fn_def| { lib2.set_script_fn(fn_def); diff --git a/src/parse.rs b/src/parse.rs index 3d1f8a71..4cf3b68e 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -2733,7 +2733,7 @@ fn parse_stmt( #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] let comments = { - let mut comments = StaticVec::>::new(); + let mut comments = Vec::>::new(); let mut comments_pos = Position::NONE; // Handle doc-comments. @@ -2996,7 +2996,7 @@ fn parse_fn( settings: ParseSettings, #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - comments: StaticVec>, + comments: Vec>, ) -> Result { let mut settings = settings; @@ -3078,7 +3078,11 @@ fn parse_fn( mods: crate::engine::Imports::new(), #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - comments, + comments: if comments.is_empty() { + None + } else { + Some(comments.into()) + }, }) } @@ -3223,7 +3227,7 @@ fn parse_anon_fn( mods: crate::engine::Imports::new(), #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - comments: StaticVec::new(), + comments: None, }; let fn_ptr = crate::FnPtr::new_unchecked(fn_name, StaticVec::new()); diff --git a/src/serde/metadata.rs b/src/serde/metadata.rs index 263dea3d..2c37f2d3 100644 --- a/src/serde/metadata.rs +++ b/src/serde/metadata.rs @@ -165,7 +165,8 @@ impl From<&crate::module::FuncInfo> for FnMetadata { .get_script_fn_def() .expect("scripted function") .comments - .to_vec() + .as_ref() + .map_or_else(|| Vec::new(), |v| v.to_vec()) } } else { Vec::new()