diff --git a/CHANGELOG.md b/CHANGELOG.md index e53f2148..2ebebf9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Breaking changes * `ModuleResolver` trait methods take an additional parameter `source_path` that contains the path of the current environment. This is to facilitate loading other script files always from the current directory. * `FileModuleResolver` now resolves relative paths under the source path if there is no base path set. * `FileModuleResolver::base_path` now returns `Option<&str>` which is `None` if there is no base path set. +* Doc-comments now require the `metadata` feature. New features ------------ diff --git a/src/ast.rs b/src/ast.rs index 9d7902d8..d7b50786 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -11,7 +11,6 @@ use crate::stdlib::{ iter::empty, num::{NonZeroU8, NonZeroUsize}, ops::{Add, AddAssign}, - string::String, vec, vec::Vec, }; @@ -65,7 +64,9 @@ pub struct ScriptFnDef { #[cfg(not(feature = "no_closure"))] pub externals: crate::stdlib::collections::BTreeSet, /// Function doc-comments (if any). - pub comments: StaticVec, + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] + pub comments: StaticVec, } impl fmt::Display for ScriptFnDef { @@ -103,6 +104,8 @@ pub struct ScriptFnMetadata<'a> { /// /// Leading white-spaces are stripped, and each string slice always starts with the corresponding /// doc-comment leader: `///` or `/**`. + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] pub comments: Vec<&'a str>, /// Function access mode. pub access: FnAccess, @@ -134,6 +137,8 @@ impl<'a> Into> for &'a ScriptFnDef { #[inline(always)] fn into(self) -> ScriptFnMetadata<'a> { ScriptFnMetadata { + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] comments: self.comments.iter().map(|s| s.as_str()).collect(), access: self.access, name: &self.name, diff --git a/src/optimize.rs b/src/optimize.rs index 03814584..7e4bcb88 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -1002,6 +1002,8 @@ pub fn optimize_into_ast( lib: None, #[cfg(not(feature = "no_module"))] mods: Default::default(), + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] comments: Default::default(), }) .for_each(|fn_def| { diff --git a/src/parser.rs b/src/parser.rs index ab0aa0bc..9bac4053 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -16,7 +16,7 @@ use crate::stdlib::{ hash::{Hash, Hasher}, iter::empty, num::{NonZeroU8, NonZeroUsize}, - string::{String, ToString}, + string::ToString, vec, vec::Vec, }; @@ -2483,10 +2483,10 @@ fn parse_stmt( ) -> Result { use AccessMode::{ReadOnly, ReadWrite}; - let mut _comments: StaticVec = Default::default(); - #[cfg(not(feature = "no_function"))] - { + #[cfg(feature = "metadata")] + let comments = { + let mut comments: StaticVec = Default::default(); let mut comments_pos = Position::NONE; // Handle doc-comments. @@ -2505,7 +2505,7 @@ fn parse_stmt( match input.next().unwrap().0 { Token::Comment(comment) => { - _comments.push(comment); + comments.push(comment); match input.peek().unwrap() { (Token::Fn, _) | (Token::Private, _) => break, @@ -2516,7 +2516,9 @@ fn parse_stmt( _ => unreachable!(), } } - } + + comments + }; let (token, token_pos) = match input.peek().unwrap() { (Token::EOF, pos) => return Ok(Stmt::Noop(*pos)), @@ -2572,7 +2574,17 @@ fn parse_stmt( pos: pos, }; - let func = parse_fn(input, &mut new_state, lib, access, settings, _comments)?; + let func = parse_fn( + input, + &mut new_state, + lib, + access, + settings, + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] + comments, + )?; + let hash = calc_fn_hash(empty(), &func.name, func.params.len()); if lib.contains_key(&hash) { @@ -2727,7 +2739,9 @@ fn parse_fn( lib: &mut FunctionsLib, access: FnAccess, mut settings: ParseSettings, - comments: StaticVec, + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] + comments: StaticVec, ) -> Result { #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2814,6 +2828,8 @@ fn parse_fn( lib: None, #[cfg(not(feature = "no_module"))] mods: Default::default(), + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] comments, }) } @@ -2967,6 +2983,8 @@ fn parse_anon_fn( lib: None, #[cfg(not(feature = "no_module"))] mods: Default::default(), + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] comments: Default::default(), };