diff --git a/CHANGELOG.md b/CHANGELOG.md index 80d2ef52..b953235b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Bug fixes * Missing `to_int` from `Decimal` is added. * Parsing of index expressions is relaxed and many cases no longer result in an index-type error to allow for custom indexers. * Merging or combining a self-contained `AST` into another `AST` now works properly. +* Plugin modules/functions no longer generate errors under `#![deny(missing_docs)]`. Deprecated API's ---------------- @@ -24,6 +25,7 @@ Enhancements * `Engine::def_tag`, `Engine::def_tag_mut` and `Engine::set_tag` are added to manage a default value for the custom evaluation state, accessible via `EvalState::tag()` (which is the same as `NativeCallContext::tag()`). * Originally, the debugger's custom state uses the same state as `EvalState::tag()` (which is the same as `NativeCallContext::tag()`). It is now split into its own variable accessible under `Debugger::state()`. * Non-borrowed string keys can now be deserialized for object maps via `serde`. +* `Scope::get` is added to get a reference to a variable's value. Version 1.7.0 diff --git a/Cargo.toml b/Cargo.toml index 5c710ef4..c96d19a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ ahash = { version = "0.7", default-features = false } num-traits = { version = "0.2", default-features = false } bitflags = { version = "1", default-features = false } smartstring = { version = "1", default-features = false } -rhai_codegen = { version = "1.4", path = "codegen", default-features = false } +rhai_codegen = { version = "1.4.1", path = "codegen", default-features = false } no-std-compat = { version = "0.4", default-features = false, features = ["alloc"], optional = true } libm = { version = "0.2", default-features = false, optional = true } diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 2cb1c662..2a9ed2c2 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhai_codegen" -version = "1.4.0" +version = "1.4.1" edition = "2018" authors = ["jhwgh1968", "Stephen Chung"] description = "Procedural macros support package for Rhai, a scripting language and engine for Rust" diff --git a/codegen/src/function.rs b/codegen/src/function.rs index e276cfa8..149f6bfb 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -620,6 +620,7 @@ impl ExportedFn { #[automatically_derived] #vis mod #name { use super::*; + #[doc(hidden)] pub struct Token(); #impl_block #dyn_result_fn_block @@ -655,6 +656,9 @@ impl ExportedFn { .resolved_at(Span::call_site()); if self.params.return_raw.is_some() { quote_spanned! { return_span => + #[allow(unused)] + #[doc(hidden)] + #[inline(always)] pub #dynamic_signature { #name(#(#arguments),*).map(Dynamic::from) } @@ -662,6 +666,7 @@ impl ExportedFn { } else { quote_spanned! { return_span => #[allow(unused)] + #[doc(hidden)] #[inline(always)] pub #dynamic_signature { Ok(Dynamic::from(#name(#(#arguments),*))) @@ -864,6 +869,7 @@ impl ExportedFn { quote! { #(#cfg_attrs)* + #[doc(hidden)] impl #type_name { #param_names #[inline(always)] pub fn param_types() -> [TypeId; #arg_count] { [#(#input_type_exprs),*] } diff --git a/codegen/src/rhai_module.rs b/codegen/src/rhai_module.rs index ccd40601..0e03917f 100644 --- a/codegen/src/rhai_module.rs +++ b/codegen/src/rhai_module.rs @@ -239,6 +239,7 @@ pub fn generate_body( gen_fn_tokens.push(quote! { #(#cfg_attrs)* #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct #fn_token_name(); }); @@ -250,6 +251,7 @@ pub fn generate_body( #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -257,6 +259,7 @@ pub fn generate_body( m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { #(#set_fn_statements)* #(#set_const_statements)* diff --git a/codegen/src/test/function.rs b/codegen/src/test/function.rs index 04d693b2..f187c5ed 100644 --- a/codegen/src/test/function.rs +++ b/codegen/src/test/function.rs @@ -275,7 +275,9 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_do_nothing { use super::*; + #[doc(hidden)] pub struct Token(); + #[doc(hidden)] impl Token { pub const PARAM_NAMES: &'static [&'static str] = &["()"]; #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } @@ -288,6 +290,7 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } } #[allow(unused)] + #[doc(hidden)] #[inline(always)] pub fn dynamic_result_fn() -> RhaiResult { Ok(Dynamic::from(do_nothing())) } @@ -308,7 +311,9 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_do_something { use super::*; + #[doc(hidden)] pub struct Token(); + #[doc(hidden)] impl Token { pub const PARAM_NAMES: &'static [&'static str] = &["x: usize", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -323,6 +328,7 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } } #[allow(unused)] + #[doc(hidden)] #[inline(always)] pub fn dynamic_result_fn(x: usize) -> RhaiResult { Ok(Dynamic::from(do_something(x))) } @@ -343,7 +349,9 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_do_something { use super::*; + #[doc(hidden)] pub struct Token(); + #[doc(hidden)] impl Token { pub const PARAM_NAMES: &'static [&'static str] = &["x: usize", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -358,6 +366,7 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } } #[allow(unused)] + #[doc(hidden)] #[inline(always)] pub fn dynamic_result_fn(context: NativeCallContext, x: usize) -> RhaiResult { Ok(Dynamic::from(do_something(context, x))) } @@ -381,7 +390,9 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_return_dynamic { use super::*; + #[doc(hidden)] pub struct Token(); + #[doc(hidden)] impl Token { pub const PARAM_NAMES: &'static [&'static str] = &["rhai::Dynamic"]; #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } @@ -395,6 +406,7 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } } #[allow(unused)] + #[doc(hidden)] #[inline(always)] pub fn dynamic_result_fn() -> RhaiResult { Ok(Dynamic::from(return_dynamic())) } @@ -412,6 +424,7 @@ mod generate_tests { }; let expected_tokens = quote! { + #[doc(hidden)] impl TestStruct { pub const PARAM_NAMES: &'static [&'static str] = &["x: usize", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -441,7 +454,9 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_add_together { use super::*; + #[doc(hidden)] pub struct Token(); + #[doc(hidden)] impl Token { pub const PARAM_NAMES: &'static [&'static str] = &["x: usize", "y: usize", "usize"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -457,6 +472,7 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } } #[allow(unused)] + #[doc(hidden)] #[inline(always)] pub fn dynamic_result_fn(x: usize, y: usize) -> RhaiResult { Ok(Dynamic::from(add_together(x, y))) } @@ -477,7 +493,9 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_increment { use super::*; + #[doc(hidden)] pub struct Token(); + #[doc(hidden)] impl Token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut usize", "y: usize", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -496,6 +514,7 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } } #[allow(unused)] + #[doc(hidden)] #[inline(always)] pub fn dynamic_result_fn(x: &mut usize, y: usize) -> RhaiResult { Ok(Dynamic::from(increment(x, y))) } @@ -517,7 +536,9 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_special_print { use super::*; + #[doc(hidden)] pub struct Token(); + #[doc(hidden)] impl Token { pub const PARAM_NAMES: &'static [&'static str] = &["message: &str", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -532,6 +553,7 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } } #[allow(unused)] + #[doc(hidden)] #[inline(always)] pub fn dynamic_result_fn(message: &str) -> RhaiResult { Ok(Dynamic::from(special_print(message))) } diff --git a/codegen/src/test/module.rs b/codegen/src/test/module.rs index be9b93e5..881746b9 100644 --- a/codegen/src/test/module.rs +++ b/codegen/src/test/module.rs @@ -323,6 +323,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -330,6 +331,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { if flatten {} else {} } @@ -358,6 +360,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -365,6 +368,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("get_mystic_number", FnNamespace::Internal, FnAccess::Public, Some(get_mystic_number_token::PARAM_NAMES), &[], @@ -372,7 +376,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct get_mystic_number_token(); + #[doc(hidden)] impl get_mystic_number_token { pub const PARAM_NAMES: &'static [&'static str] = &["INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } @@ -426,6 +432,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -433,6 +440,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn_with_comments("get_mystic_number", FnNamespace::Internal, FnAccess::Public, Some(get_mystic_number_token::PARAM_NAMES), &[], &[ @@ -445,7 +453,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct get_mystic_number_token(); + #[doc(hidden)] impl get_mystic_number_token { pub const PARAM_NAMES: &'static [&'static str] = &["INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } @@ -484,6 +494,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -491,6 +502,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("add_one_to", FnNamespace::Global, FnAccess::Public, Some(add_one_to_token::PARAM_NAMES), &[TypeId::of::()], @@ -498,7 +510,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct add_one_to_token(); + #[doc(hidden)] impl add_one_to_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -537,6 +551,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -544,6 +559,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("add_one_to", FnNamespace::Internal, FnAccess::Public, Some(add_one_to_token::PARAM_NAMES), &[TypeId::of::()], @@ -551,7 +567,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct add_one_to_token(); + #[doc(hidden)] impl add_one_to_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -601,6 +619,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -608,6 +627,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("add_n", FnNamespace::Internal, FnAccess::Public, Some(add_one_to_token::PARAM_NAMES), &[TypeId::of::()], @@ -618,7 +638,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct add_one_to_token(); + #[doc(hidden)] impl add_one_to_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -634,7 +656,9 @@ mod generate_tests { } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct add_n_to_token(); + #[doc(hidden)] impl add_n_to_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "y: INT", "INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -674,6 +698,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -681,6 +706,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("add_together", FnNamespace::Internal, FnAccess::Public, Some(add_together_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::()], @@ -688,7 +714,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct add_together_token(); + #[doc(hidden)] impl add_together_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "y: INT", "INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -729,6 +757,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -736,6 +765,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("add", FnNamespace::Internal, FnAccess::Public, Some(add_together_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::()], @@ -749,7 +779,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct add_together_token(); + #[doc(hidden)] impl add_together_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "y: INT", "INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -803,6 +835,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -810,6 +843,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("get_mystic_number", FnNamespace::Internal, FnAccess::Public, Some(get_mystic_number_token::PARAM_NAMES), &[TypeId::of::()], @@ -820,7 +854,9 @@ mod generate_tests { } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct get_mystic_number_token(); + #[doc(hidden)] impl get_mystic_number_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut Hello", "INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -858,6 +894,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -865,6 +902,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("MYSTIC_NUMBER", MYSTIC_NUMBER); if flatten {} else {} @@ -892,6 +930,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -899,6 +938,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("MYSTIC_NUMBER", MYSTIC_NUMBER); if flatten {} else {} @@ -928,6 +968,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -935,6 +976,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { if flatten {} else {} } @@ -964,6 +1006,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -971,6 +1014,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { if flatten {} else {} } @@ -1006,6 +1050,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1013,6 +1058,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("get_mystic_number", FnNamespace::Internal, FnAccess::Public, Some(get_mystic_number_token::PARAM_NAMES), &[], @@ -1020,7 +1066,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct get_mystic_number_token(); + #[doc(hidden)] impl get_mystic_number_token { pub const PARAM_NAMES: &'static [&'static str] = &["INT"]; #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } @@ -1054,6 +1102,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1061,6 +1110,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { if flatten {} else {} } @@ -1089,6 +1139,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1096,6 +1147,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, Some(print_out_to_token::PARAM_NAMES), &[TypeId::of::()], @@ -1103,7 +1155,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct print_out_to_token(); + #[doc(hidden)] impl print_out_to_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &str", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -1142,6 +1196,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1149,6 +1204,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, Some(print_out_to_token::PARAM_NAMES), &[TypeId::of::()], @@ -1156,7 +1212,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct print_out_to_token(); + #[doc(hidden)] impl print_out_to_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: String", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -1196,6 +1254,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1203,6 +1262,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("foo", FnNamespace::Internal, FnAccess::Public, Some(foo_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::()], @@ -1210,7 +1270,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct foo_token(); + #[doc(hidden)] impl foo_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut FLOAT", "y: INT", "FLOAT"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -1250,6 +1312,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1257,6 +1320,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(increment_token::PARAM_NAMES), &[TypeId::of::()], @@ -1264,7 +1328,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct increment_token(); + #[doc(hidden)] impl increment_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut FLOAT", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -1309,6 +1375,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1316,6 +1383,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(increment_token::PARAM_NAMES), &[TypeId::of::()], @@ -1323,7 +1391,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct increment_token(); + #[doc(hidden)] impl increment_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut FLOAT", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -1344,6 +1414,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1351,6 +1422,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { if flatten { { self::it_is::rhai_generate_into_module(m, flatten); } @@ -1389,6 +1461,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1396,6 +1469,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(increment_token::PARAM_NAMES), &[TypeId::of::()], @@ -1403,7 +1477,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct increment_token(); + #[doc(hidden)] impl increment_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut FLOAT", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -1424,6 +1500,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1431,6 +1508,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { if flatten { { @@ -1470,6 +1548,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1477,6 +1556,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("get$square", FnNamespace::Global, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), &[TypeId::of::()], @@ -1484,7 +1564,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct int_foo_token(); + #[doc(hidden)] impl int_foo_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut u64", "u64"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -1527,6 +1609,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1534,6 +1617,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("square", FnNamespace::Internal, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), &[TypeId::of::()], @@ -1544,7 +1628,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct int_foo_token(); + #[doc(hidden)] impl int_foo_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut u64", "u64"]; #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } @@ -1587,6 +1673,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1594,6 +1681,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("set$squared", FnNamespace::Global, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::()], @@ -1601,7 +1689,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct int_foo_token(); + #[doc(hidden)] impl int_foo_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut u64", "y: u64", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -1645,6 +1735,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1652,6 +1743,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("set_sq", FnNamespace::Internal, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::()], @@ -1662,7 +1754,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct int_foo_token(); + #[doc(hidden)] impl int_foo_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut u64", "y: u64", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -1706,6 +1800,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1713,6 +1808,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(get_by_index_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::()], @@ -1720,7 +1816,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct get_by_index_token(); + #[doc(hidden)] impl get_by_index_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "FLOAT"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -1768,6 +1866,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1775,6 +1874,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { #[cfg(hello)] m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(get_by_index_token::PARAM_NAMES), @@ -1784,8 +1884,10 @@ mod generate_tests { } #[cfg(hello)] #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct get_by_index_token(); #[cfg(hello)] + #[doc(hidden)] impl get_by_index_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "FLOAT"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -1830,6 +1932,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1837,6 +1940,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("get", FnNamespace::Internal, FnAccess::Public, Some(get_by_index_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::()], @@ -1847,7 +1951,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct get_by_index_token(); + #[doc(hidden)] impl get_by_index_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "FLOAT"]; #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } @@ -1891,6 +1997,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1898,6 +2005,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(set_by_index_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::(), TypeId::of::()], @@ -1905,7 +2013,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct set_by_index_token(); + #[doc(hidden)] impl set_by_index_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 3usize] { [TypeId::of::(), TypeId::of::(), TypeId::of::()] } @@ -1950,6 +2060,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -1957,6 +2068,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_fn("set", FnNamespace::Internal, FnAccess::Public, Some(set_by_index_token::PARAM_NAMES), &[TypeId::of::(), TypeId::of::(), TypeId::of::()], @@ -1967,7 +2079,9 @@ mod generate_tests { if flatten {} else {} } #[allow(non_camel_case_types)] + #[doc(hidden)] pub struct set_by_index_token(); + #[doc(hidden)] impl set_by_index_token { pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]; #[inline(always)] pub fn param_types() -> [TypeId; 3usize] { [TypeId::of::(), TypeId::of::(), TypeId::of::()] } @@ -2010,6 +2124,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2017,6 +2132,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("MYSTIC_NUMBER", MYSTIC_NUMBER); if flatten {} else {} @@ -2025,6 +2141,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2032,6 +2149,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { if flatten { { self::it_is::rhai_generate_into_module(m, flatten); } @@ -2067,6 +2185,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2074,6 +2193,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("MYSTIC_NUMBER", MYSTIC_NUMBER); if flatten {} else {} @@ -2085,6 +2205,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2092,6 +2213,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { #[cfg(hello)] m.set_var("SPECIAL_CPU_NUMBER", SPECIAL_CPU_NUMBER); @@ -2101,6 +2223,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2108,6 +2231,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { if flatten { { self::first_is::rhai_generate_into_module(m, flatten); } @@ -2168,6 +2292,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2175,6 +2300,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); if flatten {} else {} @@ -2185,6 +2311,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2192,6 +2319,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); if flatten {} else {} @@ -2200,6 +2328,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2207,6 +2336,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); @@ -2224,6 +2354,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2231,6 +2362,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); if flatten {} else {} @@ -2239,6 +2371,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2246,6 +2379,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); @@ -2265,6 +2399,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2272,6 +2407,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); if flatten {} else {} @@ -2282,6 +2418,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2289,6 +2426,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); if flatten {} else {} @@ -2297,6 +2435,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2304,6 +2443,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); @@ -2319,6 +2459,7 @@ mod generate_tests { #[allow(unused_imports)] use super::*; + #[doc(hidden)] pub fn rhai_module_generate() -> Module { let mut m = Module::new(); rhai_generate_into_module(&mut m, false); @@ -2326,6 +2467,7 @@ mod generate_tests { m } #[allow(unused_mut)] + #[doc(hidden)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { m.set_var("VALUE", VALUE); diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 4a22de90..32a84497 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -27,5 +27,7 @@ pub use stmt::{ #[cfg(not(feature = "no_float"))] pub use expr::FloatWrapper; +/// _(internals)_ Placeholder for a script-defined function. +/// Exported under the `internals` feature only. #[cfg(feature = "no_function")] -pub struct ScriptFnDef; +pub type ScriptFnDef = (); diff --git a/src/ast/stmt.rs b/src/ast/stmt.rs index d4c8553d..57da95dd 100644 --- a/src/ast/stmt.rs +++ b/src/ast/stmt.rs @@ -20,20 +20,20 @@ use std::{ /// /// This type may hold a straight assignment (i.e. not an op-assignment). #[derive(Clone, Copy, Eq, PartialEq, Hash)] -pub struct OpAssignment<'a> { +pub struct OpAssignment { /// Hash of the op-assignment call. pub hash_op_assign: u64, /// Hash of the underlying operator call (for fallback). pub hash_op: u64, /// Op-assignment operator. - pub op_assign: &'a str, + pub op_assign: &'static str, /// Underlying operator. - pub op: &'a str, + pub op: &'static str, /// [Position] of the op-assignment operator. pub pos: Position, } -impl OpAssignment<'_> { +impl OpAssignment { /// Create a new [`OpAssignment`] that is only a straight assignment. #[must_use] #[inline(always)] @@ -106,7 +106,7 @@ impl OpAssignment<'_> { } } -impl fmt::Debug for OpAssignment<'_> { +impl fmt::Debug for OpAssignment { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_op_assignment() { f.debug_struct("OpAssignment") @@ -194,7 +194,10 @@ pub type StmtBlockContainer = StaticVec; /// _(internals)_ A scoped block of statements. /// Exported under the `internals` feature only. #[derive(Clone, Hash, Default)] -pub struct StmtBlock(StmtBlockContainer, Span); +pub struct StmtBlock { + block: StmtBlockContainer, + span: Span, +} impl StmtBlock { /// A [`StmtBlock`] that does not exist. @@ -215,61 +218,67 @@ impl StmtBlock { pub fn new_with_span(statements: impl IntoIterator, span: Span) -> Self { let mut statements: smallvec::SmallVec<_> = statements.into_iter().collect(); statements.shrink_to_fit(); - Self(statements, span) + Self { + block: statements, + span, + } } /// Create an empty [`StmtBlock`]. #[inline(always)] #[must_use] pub const fn empty(pos: Position) -> Self { - Self(StmtBlockContainer::new_const(), Span::new(pos, pos)) + Self { + block: StmtBlockContainer::new_const(), + span: Span::new(pos, pos), + } } /// Is this statements block empty? #[inline(always)] #[must_use] pub fn is_empty(&self) -> bool { - self.0.is_empty() + self.block.is_empty() } /// Number of statements in this statements block. #[inline(always)] #[must_use] pub fn len(&self) -> usize { - self.0.len() + self.block.len() } /// Get the statements of this statements block. #[inline(always)] #[must_use] pub fn statements(&self) -> &[Stmt] { - &self.0 + &self.block } /// Extract the statements. #[inline(always)] #[must_use] pub(crate) fn take_statements(&mut self) -> StmtBlockContainer { - mem::take(&mut self.0) + mem::take(&mut self.block) } /// Get an iterator over the statements of this statements block. #[inline(always)] #[must_use] pub fn iter(&self) -> impl Iterator { - self.0.iter() + self.block.iter() } /// Get the start position (location of the beginning `{`) of this statements block. #[inline(always)] #[must_use] pub const fn position(&self) -> Position { - (self.1).start() + (self.span).start() } /// Get the end position (location of the ending `}`) of this statements block. #[inline(always)] #[must_use] pub const fn end_position(&self) -> Position { - (self.1).end() + (self.span).end() } /// Get the positions (locations of the beginning `{` and ending `}`) of this statements block. #[inline(always)] #[must_use] pub const fn span(&self) -> Span { - self.1 + self.span } /// Get the positions (locations of the beginning `{` and ending `}`) of this statements block /// or a default. @@ -277,14 +286,14 @@ impl StmtBlock { #[must_use] pub const fn span_or_else(&self, def_start_pos: Position, def_end_pos: Position) -> Span { Span::new( - (self.1).start().or_else(def_start_pos), - (self.1).end().or_else(def_end_pos), + (self.span).start().or_else(def_start_pos), + (self.span).end().or_else(def_end_pos), ) } /// Set the positions of this statements block. #[inline(always)] pub fn set_position(&mut self, start_pos: Position, end_pos: Position) { - self.1 = Span::new(start_pos, end_pos); + self.span = Span::new(start_pos, end_pos); } } @@ -293,37 +302,37 @@ impl Deref for StmtBlock { #[inline(always)] fn deref(&self) -> &Self::Target { - &self.0 + &self.block } } impl DerefMut for StmtBlock { #[inline(always)] fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 + &mut self.block } } impl AsRef<[Stmt]> for StmtBlock { #[inline(always)] fn as_ref(&self) -> &[Stmt] { - &self.0 + &self.block } } impl AsMut<[Stmt]> for StmtBlock { #[inline(always)] fn as_mut(&mut self) -> &mut [Stmt] { - &mut self.0 + &mut self.block } } impl fmt::Debug for StmtBlock { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Block")?; - fmt::Debug::fmt(&self.0, f)?; - if !self.1.is_none() { - write!(f, " @ {:?}", self.1)?; + fmt::Debug::fmt(&self.block, f)?; + if !self.span.is_none() { + write!(f, " @ {:?}", self.span())?; } Ok(()) } @@ -334,10 +343,16 @@ impl From for StmtBlock { fn from(stmt: Stmt) -> Self { match stmt { Stmt::Block(block) => *block, - Stmt::Noop(pos) => Self(StmtBlockContainer::new_const(), Span::new(pos, pos)), + Stmt::Noop(pos) => Self { + block: StmtBlockContainer::new_const(), + span: Span::new(pos, pos), + }, _ => { let pos = stmt.position(); - Self(vec![stmt].into(), Span::new(pos, Position::NONE)) + Self { + block: vec![stmt].into(), + span: Span::new(pos, Position::NONE), + } } } } @@ -352,14 +367,14 @@ impl IntoIterator for StmtBlock { #[inline(always)] fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() + self.block.into_iter() } } impl Extend for StmtBlock { #[inline(always)] fn extend>(&mut self, iter: T) { - self.0.extend(iter) + self.block.extend(iter) } } @@ -401,7 +416,7 @@ pub enum Stmt { /// * [`CONSTANT`][ASTFlags::CONSTANT] = `const` Var(Box<(Ident, Expr, Option)>, ASTFlags, Position), /// expr op`=` expr - Assignment(Box<(OpAssignment<'static>, BinaryExpr)>), + Assignment(Box<(OpAssignment, BinaryExpr)>), /// func `(` expr `,` ... `)` /// /// Note - this is a duplicate of [`Expr::FnCall`] to cover the very common pattern of a single diff --git a/src/eval/cache.rs b/src/eval/cache.rs index 8b552280..492550cf 100644 --- a/src/eval/cache.rs +++ b/src/eval/cache.rs @@ -2,9 +2,9 @@ use crate::func::CallableFunction; use crate::{Identifier, StaticVec}; -use std::collections::BTreeMap; #[cfg(feature = "no_std")] use std::prelude::v1::*; +use std::{collections::BTreeMap, marker::PhantomData}; /// _(internals)_ An entry in a function resolution cache. /// Exported under the `internals` feature only. @@ -29,40 +29,48 @@ pub type FnResolutionCache = BTreeMap>; /// The following caches are contained inside this type: /// * A stack of [function resolution caches][FnResolutionCache] #[derive(Debug, Clone)] -pub struct Caches(StaticVec); +pub struct Caches<'a> { + /// Stack of [function resolution caches][FnResolutionCache]. + fn_resolution: StaticVec, + /// Take care of the lifetime parameter. + dummy: PhantomData<&'a ()>, +} -impl Caches { +impl Caches<'_> { /// Create an empty [`Caches`]. #[inline(always)] #[must_use] pub const fn new() -> Self { - Self(StaticVec::new_const()) + Self { + fn_resolution: StaticVec::new_const(), + dummy: PhantomData, + } } /// Get the number of function resolution cache(s) in the stack. #[inline(always)] #[must_use] pub fn fn_resolution_caches_len(&self) -> usize { - self.0.len() + self.fn_resolution.len() } /// Get a mutable reference to the current function resolution cache. #[inline] #[must_use] pub fn fn_resolution_cache_mut(&mut self) -> &mut FnResolutionCache { - if self.0.is_empty() { + if self.fn_resolution.is_empty() { // Push a new function resolution cache if the stack is empty self.push_fn_resolution_cache(); } - self.0.last_mut().unwrap() + self.fn_resolution.last_mut().unwrap() } /// Push an empty function resolution cache onto the stack and make it current. #[allow(dead_code)] #[inline(always)] pub fn push_fn_resolution_cache(&mut self) { - self.0.push(BTreeMap::new()); + self.fn_resolution.push(BTreeMap::new()); } /// Rewind the function resolution caches stack to a particular size. #[inline(always)] pub fn rewind_fn_resolution_caches(&mut self, len: usize) { - self.0.truncate(len); + self.fn_resolution.truncate(len); } } diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index 11b52bf8..617b1db4 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -34,15 +34,15 @@ pub type OnDebuggerCallback = dyn Fn(EvalContext, DebuggerEvent, ASTNode, Option #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] #[non_exhaustive] pub enum DebuggerCommand { - // Continue normal execution. + /// Continue normal execution. Continue, - // Step into the next expression, diving into functions. + /// Step into the next expression, diving into functions. StepInto, - // Run to the next expression or statement, stepping over functions. + /// Run to the next expression or statement, stepping over functions. StepOver, - // Run to the next statement, skipping over functions. + /// Run to the next statement, skipping over functions. Next, - // Run to the end of the current function call. + /// Run to the end of the current function call. FunctionExit, } @@ -78,17 +78,17 @@ impl DebuggerStatus { #[derive(Debug, Clone, Copy)] #[non_exhaustive] pub enum DebuggerEvent<'a> { - // Script evaluation starts. + /// Script evaluation starts. Start, - // Break on next step. + /// Break on next step. Step, - // Break on break-point. + /// Break on break-point. BreakPoint(usize), - // Return from a function with a value. + /// Return from a function with a value. FunctionExitWithValue(&'a Dynamic), - // Return from a function with a value. + /// Return from a function with a value. FunctionExitWithError(&'a EvalAltResult), - // Script evaluation ends. + /// Script evaluation ends. End, } @@ -103,23 +103,39 @@ pub enum BreakPoint { /// Source is empty if not available. #[cfg(not(feature = "no_position"))] AtPosition { + /// Source (empty if not available) of the break-point. source: Identifier, + /// [Position] of the break-point. pos: Position, + /// Is the break-point enabled? enabled: bool, }, /// Break at a particular function call. - AtFunctionName { name: Identifier, enabled: bool }, + AtFunctionName { + /// Function name. + name: Identifier, + /// Is the break-point enabled? + enabled: bool, + }, /// Break at a particular function call with a particular number of arguments. AtFunctionCall { + /// Function name. name: Identifier, + /// Number of arguments. args: usize, + /// Is the break-point enabled? enabled: bool, }, /// Break at a particular property . /// /// Not available under `no_object`. #[cfg(not(feature = "no_object"))] - AtProperty { name: Identifier, enabled: bool }, + AtProperty { + /// Property name. + name: Identifier, + /// Is the break-point enabled? + enabled: bool, + }, } impl fmt::Display for BreakPoint { diff --git a/src/eval/eval_context.rs b/src/eval/eval_context.rs index 42041fb7..150b19e4 100644 --- a/src/eval/eval_context.rs +++ b/src/eval/eval_context.rs @@ -7,7 +7,7 @@ use std::prelude::v1::*; /// Context of a script evaluation process. #[derive(Debug)] -pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> { +pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> { /// The current [`Engine`]. engine: &'a Engine, /// The current [`Scope`]. @@ -15,7 +15,7 @@ pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> { /// The current [`GlobalRuntimeState`]. global: &'g mut GlobalRuntimeState<'pg>, /// The current [caches][Caches], if available. - caches: Option<&'c mut Caches>, + caches: Option<&'c mut Caches<'pc>>, /// The current stack of imported [modules][Module]. lib: &'a [&'a Module], /// The current bound `this` pointer, if any. @@ -24,7 +24,7 @@ pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> { level: usize, } -impl<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> { +impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> { /// Create a new [`EvalContext`]. #[inline(always)] #[must_use] @@ -32,7 +32,7 @@ impl<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't engine: &'a Engine, scope: &'s mut Scope<'ps>, global: &'g mut GlobalRuntimeState<'pg>, - caches: Option<&'c mut Caches>, + caches: Option<&'c mut Caches<'pc>>, lib: &'a [&'a Module], this_ptr: &'t mut Option<&'pt mut Dynamic>, level: usize, diff --git a/src/func/func.rs b/src/func/func.rs index 65636fbd..f74873c1 100644 --- a/src/func/func.rs +++ b/src/func/func.rs @@ -13,6 +13,7 @@ use std::prelude::v1::*; /// /// Not available under `no_function`. pub trait Func { + /// The closure's output type. type Output; /// Create a Rust closure from an [`AST`]. diff --git a/src/func/plugin.rs b/src/func/plugin.rs index dc20e6f3..7c4f84fe 100644 --- a/src/func/plugin.rs +++ b/src/func/plugin.rs @@ -10,6 +10,7 @@ pub use crate::{ use std::prelude::v1::*; pub use std::{any::TypeId, mem}; +/// Result of a Rhai function. pub type RhaiResult = crate::RhaiResult; #[cfg(not(features = "no_module"))] diff --git a/src/lib.rs b/src/lib.rs index f4a7bfff..8cd8b472 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,6 +57,7 @@ //! See [The Rhai Book](https://rhai.rs/book) for details on the Rhai scripting engine and language. #![cfg_attr(feature = "no_std", no_std)] +#![deny(missing_docs)] #[cfg(feature = "no_std")] extern crate alloc; diff --git a/src/optimizer.rs b/src/optimizer.rs index 69731719..fe3e9101 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -55,7 +55,7 @@ struct OptimizerState<'a> { /// The global runtime state. global: GlobalRuntimeState<'a>, /// Function resolution caches. - caches: Caches, + caches: Caches<'a>, /// [Module][crate::Module] containing script-defined functions. #[cfg(not(feature = "no_function"))] lib: &'a [&'a crate::Module], diff --git a/src/packages/mod.rs b/src/packages/mod.rs index 046b9cde..a4d4d612 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -97,6 +97,7 @@ macro_rules! def_package { } impl $package { + #[doc=concat!("Create a new `", stringify!($package), "`")] pub fn new() -> Self { let mut module = $crate::Module::new(); ::init(&mut module); diff --git a/src/parser.rs b/src/parser.rs index 0086f813..b25073f7 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -46,7 +46,7 @@ pub struct ParseState<'e> { /// Input stream buffer containing the next character to read. pub tokenizer_control: TokenizerControl, /// Interned strings. - interned_strings: StringsInterner, + interned_strings: StringsInterner<'e>, /// External [scope][Scope] with constants. pub scope: &'e Scope<'e>, /// Global runtime state. diff --git a/src/tokenizer.rs b/src/tokenizer.rs index ab771a0f..f75269f6 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -292,6 +292,7 @@ pub struct Span { } impl Span { + /// Empty [`Span`]. pub const NONE: Self = Self::new(Position::NONE, Position::NONE); /// Create a new [`Span`]. @@ -862,15 +863,15 @@ impl Token { }) } - // Is this token [`EOF`][Token::EOF]? + /// Is this token [`EOF`][Token::EOF]? #[inline(always)] #[must_use] pub const fn is_eof(&self) -> bool { matches!(self, Self::EOF) } - // If another operator is after these, it's probably an unary operator - // (not sure about `fn` name). + /// If another operator is after these, it's probably a unary operator + /// (not sure about `fn` name). #[must_use] pub const fn is_next_unary(&self) -> bool { use Token::*; diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index 1e36141b..8e80cb35 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -17,16 +17,19 @@ use std::{ /// A general function pointer, which may carry additional (i.e. curried) argument values /// to be passed onto a function during a call. #[derive(Clone, Hash)] -pub struct FnPtr(Identifier, StaticVec); +pub struct FnPtr { + name: Identifier, + curry: StaticVec, +} impl fmt::Debug for FnPtr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if !self.is_curried() { write!(f, "Fn({})", self.fn_name()) } else { - self.1 + self.curry .iter() - .fold(f.debug_tuple("Fn").field(&self.0), |f, curry| { + .fold(f.debug_tuple("Fn").field(&self.name), |f, curry| { f.field(curry) }) .finish() @@ -44,7 +47,10 @@ impl FnPtr { #[inline(always)] #[must_use] pub(crate) fn new_unchecked(name: impl Into, curry: StaticVec) -> Self { - Self(name.into(), curry) + Self { + name: name.into(), + curry, + } } /// Get the name of the function. #[inline(always)] @@ -56,37 +62,37 @@ impl FnPtr { #[inline(always)] #[must_use] pub(crate) const fn fn_name_raw(&self) -> &Identifier { - &self.0 + &self.name } /// Get the underlying data of the function pointer. #[inline(always)] #[must_use] pub(crate) fn take_data(self) -> (Identifier, StaticVec) { - (self.0, self.1) + (self.name, self.curry) } /// Get the curried arguments. #[inline(always)] #[must_use] pub fn curry(&self) -> &[Dynamic] { - self.1.as_ref() + self.curry.as_ref() } /// Add a new curried argument. #[inline(always)] pub fn add_curry(&mut self, value: Dynamic) -> &mut Self { - self.1.push(value); + self.curry.push(value); self } /// Set curried arguments to the function pointer. #[inline] pub fn set_curry(&mut self, values: impl IntoIterator) -> &mut Self { - self.1 = values.into_iter().collect(); + self.curry = values.into_iter().collect(); self } /// Is the function pointer curried? #[inline(always)] #[must_use] pub fn is_curried(&self) -> bool { - !self.1.is_empty() + !self.curry.is_empty() } /// Does the function pointer refer to an anonymous function? /// @@ -95,7 +101,7 @@ impl FnPtr { #[inline(always)] #[must_use] pub fn is_anonymous(&self) -> bool { - self.0.starts_with(crate::engine::FN_ANONYMOUS) + self.name.starts_with(crate::engine::FN_ANONYMOUS) } /// Call the function pointer with curried arguments (if any). /// The function may be script-defined (not available under `no_function`) or native Rust. @@ -234,7 +240,7 @@ impl FnPtr { impl fmt::Display for FnPtr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Fn({})", self.0) + write!(f, "Fn({})", self.fn_name()) } } @@ -244,7 +250,10 @@ impl TryFrom for FnPtr { #[inline] fn try_from(value: Identifier) -> RhaiResultOf { if is_valid_identifier(value.chars()) { - Ok(Self(value, StaticVec::new_const())) + Ok(Self { + name: value, + curry: StaticVec::new_const(), + }) } else { Err(ERR::ErrorFunctionNotFound(value.to_string(), Position::NONE).into()) } diff --git a/src/types/interner.rs b/src/types/interner.rs index e82152be..a5277207 100644 --- a/src/types/interner.rs +++ b/src/types/interner.rs @@ -1,14 +1,14 @@ use crate::{Identifier, ImmutableString}; #[cfg(feature = "no_std")] use std::prelude::v1::*; -use std::{collections::BTreeMap, ops::AddAssign}; +use std::{collections::BTreeMap, marker::PhantomData, ops::AddAssign}; /// _(internals)_ A factory of identifiers from text strings. /// Exported under the `internals` feature only. /// /// Normal identifiers, property getters and setters are interned separately. #[derive(Debug, Clone, Default, Hash)] -pub struct StringsInterner { +pub struct StringsInterner<'a> { /// Normal strings. strings: BTreeMap, /// Property getters. @@ -17,9 +17,11 @@ pub struct StringsInterner { /// Property setters. #[cfg(not(feature = "no_object"))] setters: BTreeMap, + /// Take care of the lifetime parameter. + dummy: PhantomData<&'a ()>, } -impl StringsInterner { +impl StringsInterner<'_> { /// Create a new [`StringsInterner`]. #[inline] #[must_use] @@ -30,6 +32,7 @@ impl StringsInterner { getters: BTreeMap::new(), #[cfg(not(feature = "no_object"))] setters: BTreeMap::new(), + dummy: PhantomData, } } /// Get an identifier from a text string and prefix, adding it to the interner if necessary. @@ -69,7 +72,7 @@ impl StringsInterner { } } -impl AddAssign for StringsInterner { +impl AddAssign for StringsInterner<'_> { #[inline(always)] fn add_assign(&mut self, rhs: Self) { self.strings.extend(rhs.strings.into_iter()); @@ -80,7 +83,7 @@ impl AddAssign for StringsInterner { } } -impl AddAssign<&Self> for StringsInterner { +impl AddAssign<&Self> for StringsInterner<'_> { #[inline(always)] fn add_assign(&mut self, rhs: &Self) { self.strings diff --git a/src/types/scope.rs b/src/types/scope.rs index 6a169bec..6b96013b 100644 --- a/src/types/scope.rs +++ b/src/types/scope.rs @@ -69,7 +69,7 @@ pub struct Scope<'a> { /// Aliases of the entry. aliases: SmallVec<[Vec; SCOPE_ENTRIES_INLINED]>, /// Phantom to keep the lifetime parameter in order not to break existing code. - phantom: PhantomData<&'a ()>, + dummy: PhantomData<&'a ()>, } impl fmt::Display for Scope<'_> { @@ -112,7 +112,7 @@ impl Clone for Scope<'_> { .collect(), names: self.names.clone(), aliases: self.aliases.clone(), - phantom: self.phantom.clone(), + dummy: self.dummy.clone(), } } } @@ -152,7 +152,7 @@ impl Scope<'_> { values: SmallVec::new_const(), names: SmallVec::new_const(), aliases: SmallVec::new_const(), - phantom: PhantomData, + dummy: PhantomData, } } /// Empty the [`Scope`]. @@ -511,9 +511,33 @@ impl Scope<'_> { } self } + /// Get a reference to an entry in the [`Scope`]. + /// + /// If the entry by the specified name is not found, [`None`] is returned. + /// + /// # Example + /// + /// ``` + /// use rhai::Scope; + /// + /// let mut my_scope = Scope::new(); + /// + /// my_scope.push("x", 42_i64); + /// + /// let value = my_scope.get("x").expect("x should exist"); + /// + /// assert_eq!(value.as_int().unwrap(), 42); + /// + /// assert!(my_scope.get("z").is_none()); + /// ``` + #[inline(always)] + #[must_use] + pub fn get(&self, name: &str) -> Option<&Dynamic> { + self.get_index(name).map(|(index, _)| &self.values[index]) + } /// Get a mutable reference to an entry in the [`Scope`]. /// - /// If the entry by the specified name is not found, of if it is read-only, + /// If the entry by the specified name is not found, or if it is read-only, /// [`None`] is returned. /// /// # Example @@ -531,8 +555,8 @@ impl Scope<'_> { /// /// assert_eq!(my_scope.get_value::("x").expect("x should exist"), 123); /// - /// my_scope.push_constant("Z", 1_i64); - /// assert!(my_scope.get_mut("Z").is_none()); + /// my_scope.push_constant("z", 1_i64); + /// assert!(my_scope.get_mut("z").is_none()); /// ``` #[inline] #[must_use] diff --git a/tests/plugins.rs b/tests/plugins.rs index 5327595c..85833a54 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -121,8 +121,6 @@ fn test_plugins_package() -> Result<(), Box> { fn test_plugins_parameters() -> Result<(), Box> { #[export_module] mod rhai_std { - use rhai::*; - pub fn noop(_: &str) {} }