diff --git a/CHANGELOG.md b/CHANGELOG.md index 6195c77d4..8cdf5d08f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,19 +8,20 @@ Bug fixes --------- * `Engine::compact_script` now properly compacts scripts with custom syntax that uses `$raw$` (thanks [`@yuvalrakavy`](https://github.com/yuvalrakavy) [`#1079`](https://github.com/rhaiscript/rhai/pull/1079)). -* The string methods `split`, `split_rev` and their variants are now marked pure so they can be called on `const` strings ([`#1081`](https://github.com/rhaiscript/rhai/issues/1081)). +* The string methods `split`, `split_rev` and their variants are now marked `pure` so they can be called on constant strings (thanks [`@theJC`](https://github.com/theJC) [`#1082`](https://github.com/rhaiscript/rhai/pull/1082)). New features ------------ * A new advanced callback, `Engine::on_missing_function`, is added (gated under the `internals` feature) to override default handling when a called function or method is not found (thanks [`@yuvalrakavy`](https://github.com/yuvalrakavy) [`#1067`](https://github.com/rhaiscript/rhai/pull/1067)). +* A new method, `EvalContext::new_frame`, is added to created an isolated frame guard that automatically restores field values upon `Drop` (thanks [`@yuvalrakavy`](https://github.com/yuvalrakavy) for the idea [`#1085`](https://github.com/rhaiscript/rhai/pull/1085)). Enhancements ------------ * Procedural macros such as `#[export_module]` and `#[derive(CustomType)]` no longer require importing standard Rhai types (thanks [`@timokoesters`](https://github.com/timokoesters) [`#1071`](https://github.com/rhaiscript/rhai/pull/1071)). -* `FnPtr::call_fn_as_method` and `FnPtr::call_as_method_within_context` are added (when not under `no_object`) to accept a `this` pointer for calling the function pointer as a method call. -* `NativeCallContext::call_method` and `NativeCallContext::call_native_method` are added (when not under `no_object`) to accept a `this` pointer for method calls. +* `FnPtr::call_fn_as_method` and `FnPtr::call_as_method_within_context` are added (when not under `no_object`) to accept a `this` pointer for calling the function pointer as a method call ([`#1080`](https://github.com/rhaiscript/rhai/pull/1080)). +* `NativeCallContext::call_method` and `NativeCallContext::call_native_method` are added (when not under `no_object`) to accept a `this` pointer for method calls ([`#1080`](https://github.com/rhaiscript/rhai/pull/1080)). Version 1.24.0 diff --git a/codegen/ui_tests/export_fn_bad_attr.stderr b/codegen/ui_tests/export_fn_bad_attr.stderr index 9e7ed6fdb..d978d50b6 100644 --- a/codegen/ui_tests/export_fn_bad_attr.stderr +++ b/codegen/ui_tests/export_fn_bad_attr.stderr @@ -3,9 +3,3 @@ error: unknown attribute 'unknown' | 10 | #[export_fn(unknown = "thing")] | ^^^^^^^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/export_fn_bad_attr.rs:17:8 - | -17 | if test_fn(n) { - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/export_fn_bad_value.stderr b/codegen/ui_tests/export_fn_bad_value.stderr index 3ec6d890b..114d6ec65 100644 --- a/codegen/ui_tests/export_fn_bad_value.stderr +++ b/codegen/ui_tests/export_fn_bad_value.stderr @@ -3,9 +3,3 @@ error: expecting string literal | 10 | #[export_fn(name = true)] | ^^^^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/export_fn_bad_value.rs:17:8 - | -17 | if test_fn(n) { - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/export_fn_extra_value.stderr b/codegen/ui_tests/export_fn_extra_value.stderr index 5f0a86e4b..e77b8b356 100644 --- a/codegen/ui_tests/export_fn_extra_value.stderr +++ b/codegen/ui_tests/export_fn_extra_value.stderr @@ -3,9 +3,3 @@ error: extraneous value | 10 | #[export_fn(return_raw = "yes")] | ^^^^^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/export_fn_extra_value.rs:17:8 - | -17 | if test_fn(n) { - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/export_fn_junk_arg.stderr b/codegen/ui_tests/export_fn_junk_arg.stderr index 973984e53..d7f7d03cc 100644 --- a/codegen/ui_tests/export_fn_junk_arg.stderr +++ b/codegen/ui_tests/export_fn_junk_arg.stderr @@ -3,9 +3,3 @@ error: expecting identifier | 10 | #[export_fn("wheeeee")] | ^^^^^^^^^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/export_fn_junk_arg.rs:17:8 - | -17 | if test_fn(n) { - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/export_fn_missing_value.stderr b/codegen/ui_tests/export_fn_missing_value.stderr index 7e8b8e142..53049e15a 100644 --- a/codegen/ui_tests/export_fn_missing_value.stderr +++ b/codegen/ui_tests/export_fn_missing_value.stderr @@ -3,9 +3,3 @@ error: requires value | 10 | #[export_fn(name)] | ^^^^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/export_fn_missing_value.rs:17:8 - | -17 | if test_fn(n) { - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/export_fn_path_attr.stderr b/codegen/ui_tests/export_fn_path_attr.stderr index 3646601ed..3d7b82c0a 100644 --- a/codegen/ui_tests/export_fn_path_attr.stderr +++ b/codegen/ui_tests/export_fn_path_attr.stderr @@ -3,9 +3,3 @@ error: expecting attribute name | 10 | #[export_fn(rhai::name = "thing")] | ^^^^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/export_fn_path_attr.rs:17:8 - | -17 | if test_fn(n) { - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/export_fn_raw_noreturn.stderr b/codegen/ui_tests/export_fn_raw_noreturn.stderr index 29c12712c..bc040a956 100644 --- a/codegen/ui_tests/export_fn_raw_noreturn.stderr +++ b/codegen/ui_tests/export_fn_raw_noreturn.stderr @@ -3,9 +3,3 @@ error: functions marked with 'return_raw' must return Result ui_tests/export_fn_raw_noreturn.rs:17:5 - | -17 | test_fn(&mut n); - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/export_mod_bad_attr.stderr b/codegen/ui_tests/export_mod_bad_attr.stderr index b8f837e28..35e5d1fc1 100644 --- a/codegen/ui_tests/export_mod_bad_attr.stderr +++ b/codegen/ui_tests/export_mod_bad_attr.stderr @@ -3,11 +3,3 @@ error: unknown attribute 'unknown' | 11 | #[rhai_fn(unknown = "thing")] | ^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_mod` - --> ui_tests/export_mod_bad_attr.rs:22:8 - | -22 | if test_mod::test_fn(n) { - | ^^^^^^^^ use of unresolved module or unlinked crate `test_mod` - | - = help: if you wanted to use a crate named `test_mod`, use `cargo add test_mod` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/export_mod_bad_value.stderr b/codegen/ui_tests/export_mod_bad_value.stderr index ce9528db0..8f0f5c3d3 100644 --- a/codegen/ui_tests/export_mod_bad_value.stderr +++ b/codegen/ui_tests/export_mod_bad_value.stderr @@ -3,11 +3,3 @@ error: expecting string literal | 11 | #[rhai_fn(name = true)] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_mod` - --> ui_tests/export_mod_bad_value.rs:22:8 - | -22 | if test_mod::test_fn(n) { - | ^^^^^^^^ use of unresolved module or unlinked crate `test_mod` - | - = help: if you wanted to use a crate named `test_mod`, use `cargo add test_mod` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/export_mod_cfg.stderr b/codegen/ui_tests/export_mod_cfg.stderr index cbe179278..6c7c0dd33 100644 --- a/codegen/ui_tests/export_mod_cfg.stderr +++ b/codegen/ui_tests/export_mod_cfg.stderr @@ -3,11 +3,3 @@ error: expected attribute arguments in parentheses: #[rhai_fn(...)] | 12 | #[rhai_fn] | ^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_mod` - --> ui_tests/export_mod_cfg.rs:23:8 - | -23 | if test_mod::test_fn(n) { - | ^^^^^^^^ use of unresolved module or unlinked crate `test_mod` - | - = help: if you wanted to use a crate named `test_mod`, use `cargo add test_mod` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/export_mod_extra_value.stderr b/codegen/ui_tests/export_mod_extra_value.stderr index bba695f32..7b3e24362 100644 --- a/codegen/ui_tests/export_mod_extra_value.stderr +++ b/codegen/ui_tests/export_mod_extra_value.stderr @@ -3,11 +3,3 @@ error: extraneous value | 11 | #[rhai_fn(return_raw = "yes")] | ^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_mod` - --> ui_tests/export_mod_extra_value.rs:22:8 - | -22 | if test_mod::test_fn(n) { - | ^^^^^^^^ use of unresolved module or unlinked crate `test_mod` - | - = help: if you wanted to use a crate named `test_mod`, use `cargo add test_mod` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/export_mod_junk_arg.stderr b/codegen/ui_tests/export_mod_junk_arg.stderr index 0b193771c..4c14944ca 100644 --- a/codegen/ui_tests/export_mod_junk_arg.stderr +++ b/codegen/ui_tests/export_mod_junk_arg.stderr @@ -3,11 +3,3 @@ error: expecting identifier | 11 | #[rhai_fn("wheeeee")] | ^^^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_mod` - --> ui_tests/export_mod_junk_arg.rs:22:8 - | -22 | if test_mod::test_fn(n) { - | ^^^^^^^^ use of unresolved module or unlinked crate `test_mod` - | - = help: if you wanted to use a crate named `test_mod`, use `cargo add test_mod` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/export_mod_missing_value.stderr b/codegen/ui_tests/export_mod_missing_value.stderr index eeea616f9..147f84c73 100644 --- a/codegen/ui_tests/export_mod_missing_value.stderr +++ b/codegen/ui_tests/export_mod_missing_value.stderr @@ -3,11 +3,3 @@ error: requires value | 11 | #[rhai_fn(name)] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_mod` - --> ui_tests/export_mod_missing_value.rs:22:8 - | -22 | if test_mod::test_fn(n) { - | ^^^^^^^^ use of unresolved module or unlinked crate `test_mod` - | - = help: if you wanted to use a crate named `test_mod`, use `cargo add test_mod` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/export_mod_path_attr.stderr b/codegen/ui_tests/export_mod_path_attr.stderr index 49ff65297..f17cd7582 100644 --- a/codegen/ui_tests/export_mod_path_attr.stderr +++ b/codegen/ui_tests/export_mod_path_attr.stderr @@ -3,11 +3,3 @@ error: expecting attribute name | 11 | #[rhai_fn(rhai::name = "thing")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_mod` - --> ui_tests/export_mod_path_attr.rs:22:8 - | -22 | if test_mod::test_fn(n) { - | ^^^^^^^^ use of unresolved module or unlinked crate `test_mod` - | - = help: if you wanted to use a crate named `test_mod`, use `cargo add test_mod` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/export_mod_raw_noreturn.stderr b/codegen/ui_tests/export_mod_raw_noreturn.stderr index 30c93bd3b..656613ee2 100644 --- a/codegen/ui_tests/export_mod_raw_noreturn.stderr +++ b/codegen/ui_tests/export_mod_raw_noreturn.stderr @@ -3,11 +3,3 @@ error: functions marked with 'return_raw' must return Result ui_tests/export_mod_raw_noreturn.rs:22:5 - | -22 | test_mod::test_fn(&mut n); - | ^^^^^^^^ use of unresolved module or unlinked crate `test_mod` - | - = help: if you wanted to use a crate named `test_mod`, use `cargo add test_mod` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/first_shared_ref.stderr b/codegen/ui_tests/first_shared_ref.stderr index 462cfd2fe..bcefd462d 100644 --- a/codegen/ui_tests/first_shared_ref.stderr +++ b/codegen/ui_tests/first_shared_ref.stderr @@ -3,9 +3,3 @@ error: references from Rhai in this position must be mutable | 12 | pub fn test_fn(input: &NonClonable) -> bool { | ^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/first_shared_ref.rs:23:8 - | -23 | if test_fn(n) { - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/return_mut_ref.stderr b/codegen/ui_tests/return_mut_ref.stderr index 8f69c9b1d..99747982b 100644 --- a/codegen/ui_tests/return_mut_ref.stderr +++ b/codegen/ui_tests/return_mut_ref.stderr @@ -3,9 +3,3 @@ error: Rhai functions cannot return references | 14 | pub fn test_fn(input: &mut Clonable) -> &mut bool { | ^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/return_mut_ref.rs:25:8 - | -25 | if test_fn(n) { - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/return_pointer.stderr b/codegen/ui_tests/return_pointer.stderr index c6674b4a4..5bca2651a 100644 --- a/codegen/ui_tests/return_pointer.stderr +++ b/codegen/ui_tests/return_pointer.stderr @@ -3,9 +3,3 @@ error: Rhai functions cannot return pointers | 13 | pub fn test_fn(input: Clonable) -> *const str { | ^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/return_pointer.rs:25:19 - | -25 | let ptr = test_fn(n); - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/return_shared_ref.stderr b/codegen/ui_tests/return_shared_ref.stderr index 01a1b2963..f12f82411 100644 --- a/codegen/ui_tests/return_shared_ref.stderr +++ b/codegen/ui_tests/return_shared_ref.stderr @@ -3,9 +3,3 @@ error: Rhai functions cannot return references | 13 | pub fn test_fn(input: Clonable) -> &'static str { | ^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/return_shared_ref.rs:24:20 - | -24 | println!("{}", test_fn(n)); - | ^^^^^^^ not found in this scope diff --git a/codegen/ui_tests/rhai_fn_bad_attr.stderr b/codegen/ui_tests/rhai_fn_bad_attr.stderr index b45b44285..074e10a8b 100644 --- a/codegen/ui_tests/rhai_fn_bad_attr.stderr +++ b/codegen/ui_tests/rhai_fn_bad_attr.stderr @@ -3,11 +3,3 @@ error: unknown attribute 'unknown' | 11 | #[rhai_fn(unknown = "thing")] | ^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_bad_attr.rs:22:8 - | -22 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_bad_value.stderr b/codegen/ui_tests/rhai_fn_bad_value.stderr index 0e034e33c..378379839 100644 --- a/codegen/ui_tests/rhai_fn_bad_value.stderr +++ b/codegen/ui_tests/rhai_fn_bad_value.stderr @@ -3,11 +3,3 @@ error: expecting string literal | 11 | #[rhai_fn(name = true)] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_bad_value.rs:22:8 - | -22 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_duplicate_attr.stderr b/codegen/ui_tests/rhai_fn_duplicate_attr.stderr index d0790fb8d..bf9213c33 100644 --- a/codegen/ui_tests/rhai_fn_duplicate_attr.stderr +++ b/codegen/ui_tests/rhai_fn_duplicate_attr.stderr @@ -3,17 +3,3 @@ error: duplicated attribute 'rhai_fn' | 6 | #[rhai_fn(pure)] | ^ - -error[E0425]: cannot find value `n` in this scope - --> ui_tests/rhai_fn_duplicate_attr.rs:13:29 - | -13 | if test_module::test_fn(n) { - | ^ not found in this scope - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_duplicate_attr.rs:13:8 - | -13 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_extra_value.stderr b/codegen/ui_tests/rhai_fn_extra_value.stderr index b7f848cc8..db5f7cc8f 100644 --- a/codegen/ui_tests/rhai_fn_extra_value.stderr +++ b/codegen/ui_tests/rhai_fn_extra_value.stderr @@ -3,11 +3,3 @@ error: extraneous value | 11 | #[rhai_fn(return_raw = "yes")] | ^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_extra_value.rs:22:8 - | -22 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_getter_conflict.stderr b/codegen/ui_tests/rhai_fn_getter_conflict.stderr index eca6b082d..1bf51dc59 100644 --- a/codegen/ui_tests/rhai_fn_getter_conflict.stderr +++ b/codegen/ui_tests/rhai_fn_getter_conflict.stderr @@ -3,11 +3,3 @@ error: conflicting setter | 12 | #[rhai_fn(name = "foo", get = "foo", set = "bar")] | ^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_getter_conflict.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_getter_multiple.stderr b/codegen/ui_tests/rhai_fn_getter_multiple.stderr index 0ee73e7d1..2f2739ed7 100644 --- a/codegen/ui_tests/rhai_fn_getter_multiple.stderr +++ b/codegen/ui_tests/rhai_fn_getter_multiple.stderr @@ -3,11 +3,3 @@ error: conflicting getter | 12 | #[rhai_fn(name = "foo", get = "foo", get = "bar")] | ^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_getter_multiple.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_getter_return.stderr b/codegen/ui_tests/rhai_fn_getter_return.stderr index a10de0a34..83e2eee1b 100644 --- a/codegen/ui_tests/rhai_fn_getter_return.stderr +++ b/codegen/ui_tests/rhai_fn_getter_return.stderr @@ -3,11 +3,3 @@ error: property getter must return a value | 13 | pub fn test_fn(input: &mut Point) { | ^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_getter_return.rs:23:5 - | -23 | test_module::test_fn(&mut n); - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_getter_signature.stderr b/codegen/ui_tests/rhai_fn_getter_signature.stderr index ea18e086e..dbc60f52c 100644 --- a/codegen/ui_tests/rhai_fn_getter_signature.stderr +++ b/codegen/ui_tests/rhai_fn_getter_signature.stderr @@ -3,11 +3,3 @@ error: property getter requires exactly 1 parameter | 13 | pub fn test_fn(input: Point, value: bool) -> bool { | ^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_getter_signature.rs:23:8 - | -23 | if test_module::test_fn(n, true) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_global_multiple.stderr b/codegen/ui_tests/rhai_fn_global_multiple.stderr index ea2c3ef14..1cd485f7e 100644 --- a/codegen/ui_tests/rhai_fn_global_multiple.stderr +++ b/codegen/ui_tests/rhai_fn_global_multiple.stderr @@ -3,11 +3,3 @@ error: namespace is already set to 'global' | 12 | #[rhai_fn(global, internal)] | ^^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_global_multiple.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_index_getter_multiple.stderr b/codegen/ui_tests/rhai_fn_index_getter_multiple.stderr index 7e72dcad8..52e3cadac 100644 --- a/codegen/ui_tests/rhai_fn_index_getter_multiple.stderr +++ b/codegen/ui_tests/rhai_fn_index_getter_multiple.stderr @@ -3,11 +3,3 @@ error: conflicting index_get | 12 | #[rhai_fn(name = "foo", index_get, index_get)] | ^^^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_index_getter_multiple.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_index_getter_return.stderr b/codegen/ui_tests/rhai_fn_index_getter_return.stderr index 20fd36508..52262ab87 100644 --- a/codegen/ui_tests/rhai_fn_index_getter_return.stderr +++ b/codegen/ui_tests/rhai_fn_index_getter_return.stderr @@ -3,11 +3,3 @@ error: index getter must return a value | 13 | pub fn test_fn(input: &mut Point, i: f32) { | ^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_index_getter_return.rs:23:8 - | -23 | if test_module::test_fn(&mut n, 5.0) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_index_getter_signature.stderr b/codegen/ui_tests/rhai_fn_index_getter_signature.stderr index 7a5ca4cdb..b783e27a9 100644 --- a/codegen/ui_tests/rhai_fn_index_getter_signature.stderr +++ b/codegen/ui_tests/rhai_fn_index_getter_signature.stderr @@ -3,11 +3,3 @@ error: index getter requires exactly 2 parameters | 13 | pub fn test_fn(input: Point) -> bool { | ^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_index_getter_signature.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_index_setter_multiple.stderr b/codegen/ui_tests/rhai_fn_index_setter_multiple.stderr index 088d20131..e95ca52f9 100644 --- a/codegen/ui_tests/rhai_fn_index_setter_multiple.stderr +++ b/codegen/ui_tests/rhai_fn_index_setter_multiple.stderr @@ -3,11 +3,3 @@ error: conflicting index_set | 12 | #[rhai_fn(name = "foo", index_set, index_set)] | ^^^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_index_setter_multiple.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_junk_arg.stderr b/codegen/ui_tests/rhai_fn_junk_arg.stderr index 54f32a97b..d37040cb1 100644 --- a/codegen/ui_tests/rhai_fn_junk_arg.stderr +++ b/codegen/ui_tests/rhai_fn_junk_arg.stderr @@ -3,11 +3,3 @@ error: expecting identifier | 11 | #[rhai_fn("wheeeee")] | ^^^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_junk_arg.rs:22:8 - | -22 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_missing_value.stderr b/codegen/ui_tests/rhai_fn_missing_value.stderr index 48d0310ee..adcb74db6 100644 --- a/codegen/ui_tests/rhai_fn_missing_value.stderr +++ b/codegen/ui_tests/rhai_fn_missing_value.stderr @@ -3,11 +3,3 @@ error: requires value | 11 | #[rhai_fn(name)] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_missing_value.rs:22:8 - | -22 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_path_attr.stderr b/codegen/ui_tests/rhai_fn_path_attr.stderr index 3715577c1..c0e34991e 100644 --- a/codegen/ui_tests/rhai_fn_path_attr.stderr +++ b/codegen/ui_tests/rhai_fn_path_attr.stderr @@ -3,11 +3,3 @@ error: expecting attribute name | 11 | #[rhai_fn(rhai::name = "thing")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_path_attr.rs:22:8 - | -22 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_rename_collision.stderr b/codegen/ui_tests/rhai_fn_rename_collision.stderr index ee57e6c85..789788b0c 100644 --- a/codegen/ui_tests/rhai_fn_rename_collision.stderr +++ b/codegen/ui_tests/rhai_fn_rename_collision.stderr @@ -9,11 +9,3 @@ error: duplicated function renamed 'foo' | 12 | #[rhai_fn(name = "foo")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_rename_collision.rs:28:8 - | -28 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_rename_collision_oneattr.stderr b/codegen/ui_tests/rhai_fn_rename_collision_oneattr.stderr index 7f0289ee8..6461d5c1d 100644 --- a/codegen/ui_tests/rhai_fn_rename_collision_oneattr.stderr +++ b/codegen/ui_tests/rhai_fn_rename_collision_oneattr.stderr @@ -9,11 +9,3 @@ error: duplicated function 'foo' | 12 | #[rhai_fn(name = "foo")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_rename_collision_oneattr.rs:27:8 - | -27 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_rename_collision_oneattr_multiple.stderr b/codegen/ui_tests/rhai_fn_rename_collision_oneattr_multiple.stderr index 835643783..195ed3a31 100644 --- a/codegen/ui_tests/rhai_fn_rename_collision_oneattr_multiple.stderr +++ b/codegen/ui_tests/rhai_fn_rename_collision_oneattr_multiple.stderr @@ -9,11 +9,3 @@ error: duplicated function renamed 'bar' | 12 | #[rhai_fn(name = "foo", get = "bar")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_rename_collision_oneattr_multiple.rs:25:8 - | -25 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_rename_collision_with_itself.stderr b/codegen/ui_tests/rhai_fn_rename_collision_with_itself.stderr index d46548a95..f900cbd06 100644 --- a/codegen/ui_tests/rhai_fn_rename_collision_with_itself.stderr +++ b/codegen/ui_tests/rhai_fn_rename_collision_with_itself.stderr @@ -9,11 +9,3 @@ error: duplicated function renamed 'foo' | 12 | #[rhai_fn(name = "foo", name = "bar", name = "foo")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_rename_collision_with_itself.rs:20:8 - | -20 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_rename_to_index_getter.stderr b/codegen/ui_tests/rhai_fn_rename_to_index_getter.stderr index f469d2c4f..1ed4a2018 100644 --- a/codegen/ui_tests/rhai_fn_rename_to_index_getter.stderr +++ b/codegen/ui_tests/rhai_fn_rename_to_index_getter.stderr @@ -3,11 +3,3 @@ error: use attribute 'index_get' instead | 12 | #[rhai_fn(name = "index$get$")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_rename_to_index_getter.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_rename_to_index_setter.stderr b/codegen/ui_tests/rhai_fn_rename_to_index_setter.stderr index 754b68b77..9ea12eee8 100644 --- a/codegen/ui_tests/rhai_fn_rename_to_index_setter.stderr +++ b/codegen/ui_tests/rhai_fn_rename_to_index_setter.stderr @@ -3,11 +3,3 @@ error: use attribute 'index_set' instead | 12 | #[rhai_fn(name = "index$set$")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_rename_to_index_setter.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_rename_to_prop_getter.stderr b/codegen/ui_tests/rhai_fn_rename_to_prop_getter.stderr index dcac3ea93..34dbda0f8 100644 --- a/codegen/ui_tests/rhai_fn_rename_to_prop_getter.stderr +++ b/codegen/ui_tests/rhai_fn_rename_to_prop_getter.stderr @@ -3,11 +3,3 @@ error: use attribute 'getter = "foo"' instead | 12 | #[rhai_fn(name = "get$foo")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_rename_to_prop_getter.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_rename_to_prop_setter.stderr b/codegen/ui_tests/rhai_fn_rename_to_prop_setter.stderr index dbd176d84..338e121ef 100644 --- a/codegen/ui_tests/rhai_fn_rename_to_prop_setter.stderr +++ b/codegen/ui_tests/rhai_fn_rename_to_prop_setter.stderr @@ -3,11 +3,3 @@ error: use attribute 'getter = "foo"' instead | 12 | #[rhai_fn(name = "get$foo")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_rename_to_prop_setter.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_setter_index_signature.stderr b/codegen/ui_tests/rhai_fn_setter_index_signature.stderr index c5f3ab996..fb388e0e1 100644 --- a/codegen/ui_tests/rhai_fn_setter_index_signature.stderr +++ b/codegen/ui_tests/rhai_fn_setter_index_signature.stderr @@ -3,11 +3,3 @@ error: index setter requires exactly 3 parameters | 13 | pub fn test_fn(input: Point) -> bool { | ^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_setter_index_signature.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_setter_multiple.stderr b/codegen/ui_tests/rhai_fn_setter_multiple.stderr index 3be5094fb..7e04a1876 100644 --- a/codegen/ui_tests/rhai_fn_setter_multiple.stderr +++ b/codegen/ui_tests/rhai_fn_setter_multiple.stderr @@ -3,11 +3,3 @@ error: conflicting setter | 12 | #[rhai_fn(name = "foo", set = "foo", set = "bar")] | ^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_setter_multiple.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_setter_return.stderr b/codegen/ui_tests/rhai_fn_setter_return.stderr index 71b8fc478..d024e6be7 100644 --- a/codegen/ui_tests/rhai_fn_setter_return.stderr +++ b/codegen/ui_tests/rhai_fn_setter_return.stderr @@ -3,11 +3,3 @@ error: property setter cannot return any value | 13 | pub fn test_fn(input: &mut Point, value: f32) -> bool { | ^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_setter_return.rs:24:8 - | -24 | if test_module::test_fn(&mut n, 5.0) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_fn_setter_signature.stderr b/codegen/ui_tests/rhai_fn_setter_signature.stderr index 79b5088db..7abea1989 100644 --- a/codegen/ui_tests/rhai_fn_setter_signature.stderr +++ b/codegen/ui_tests/rhai_fn_setter_signature.stderr @@ -3,11 +3,3 @@ error: property setter requires exactly 2 parameters | 13 | pub fn test_fn(input: Point) -> bool { | ^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_fn_setter_signature.rs:23:8 - | -23 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_mod_bad_attr.stderr b/codegen/ui_tests/rhai_mod_bad_attr.stderr index 17c8f012f..3fb1f5f48 100644 --- a/codegen/ui_tests/rhai_mod_bad_attr.stderr +++ b/codegen/ui_tests/rhai_mod_bad_attr.stderr @@ -3,11 +3,3 @@ error: unknown attribute 'unknown' | 11 | #[rhai_mod(unknown = "thing")] | ^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_mod_bad_attr.rs:24:8 - | -24 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_mod_bad_value.stderr b/codegen/ui_tests/rhai_mod_bad_value.stderr index 68dfb4536..0ad184a48 100644 --- a/codegen/ui_tests/rhai_mod_bad_value.stderr +++ b/codegen/ui_tests/rhai_mod_bad_value.stderr @@ -3,11 +3,3 @@ error: expecting string literal | 11 | #[rhai_mod(name = true)] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_mod_bad_value.rs:24:8 - | -24 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_mod_inner_cfg_false.stderr b/codegen/ui_tests/rhai_mod_inner_cfg_false.stderr index b690c6818..69f2be274 100644 --- a/codegen/ui_tests/rhai_mod_inner_cfg_false.stderr +++ b/codegen/ui_tests/rhai_mod_inner_cfg_false.stderr @@ -1,4 +1,4 @@ -error[E0433]: failed to resolve: could not find `test_mod` in `test_module` +error[E0433]: cannot find `test_mod` in `test_module` --> ui_tests/rhai_mod_inner_cfg_false.rs:24:21 | 24 | if test_module::test_mod::test_fn(n) { diff --git a/codegen/ui_tests/rhai_mod_junk_arg.stderr b/codegen/ui_tests/rhai_mod_junk_arg.stderr index 9a9803590..9bf2a69e1 100644 --- a/codegen/ui_tests/rhai_mod_junk_arg.stderr +++ b/codegen/ui_tests/rhai_mod_junk_arg.stderr @@ -3,11 +3,3 @@ error: expecting identifier | 11 | #[rhai_mod("wheeeee")] | ^^^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_mod_junk_arg.rs:24:8 - | -24 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_mod_missing_value.stderr b/codegen/ui_tests/rhai_mod_missing_value.stderr index 6454586e5..c696fa766 100644 --- a/codegen/ui_tests/rhai_mod_missing_value.stderr +++ b/codegen/ui_tests/rhai_mod_missing_value.stderr @@ -3,11 +3,3 @@ error: requires value | 11 | #[rhai_mod(name)] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_mod_missing_value.rs:24:8 - | -24 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_mod_name_collisions.stderr b/codegen/ui_tests/rhai_mod_name_collisions.stderr index 5cfee9e32..7bcf0b09f 100644 --- a/codegen/ui_tests/rhai_mod_name_collisions.stderr +++ b/codegen/ui_tests/rhai_mod_name_collisions.stderr @@ -9,11 +9,3 @@ error: duplicated function 'test_fn' | 12 | pub fn test_fn(input: Point) -> bool { | ^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_mod_name_collisions.rs:26:8 - | -26 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_mod_path_attr.stderr b/codegen/ui_tests/rhai_mod_path_attr.stderr index f89b86ea8..024604815 100644 --- a/codegen/ui_tests/rhai_mod_path_attr.stderr +++ b/codegen/ui_tests/rhai_mod_path_attr.stderr @@ -3,11 +3,3 @@ error: expecting attribute name | 11 | #[rhai_mod(rhai::name = "thing")] | ^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_mod_path_attr.rs:24:8 - | -24 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/rhai_mod_return_raw.stderr b/codegen/ui_tests/rhai_mod_return_raw.stderr index a3bc4fc6a..ae202928a 100644 --- a/codegen/ui_tests/rhai_mod_return_raw.stderr +++ b/codegen/ui_tests/rhai_mod_return_raw.stderr @@ -3,11 +3,3 @@ error: unknown attribute 'return_raw' | 11 | #[rhai_mod(return_raw = "yes")] | ^^^^^^^^^^ - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `test_module` - --> ui_tests/rhai_mod_return_raw.rs:24:8 - | -24 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of unresolved module or unlinked crate `test_module` - | - = help: if you wanted to use a crate named `test_module`, use `cargo add test_module` to add it to your `Cargo.toml` diff --git a/codegen/ui_tests/second_shared_ref.stderr b/codegen/ui_tests/second_shared_ref.stderr index 1ef27bb81..0ac06235c 100644 --- a/codegen/ui_tests/second_shared_ref.stderr +++ b/codegen/ui_tests/second_shared_ref.stderr @@ -3,9 +3,3 @@ error: function parameters other than the first one cannot be passed by referenc | 13 | pub fn test_fn(input: Clonable, factor: &bool) -> bool { | ^ - -error[E0425]: cannot find function `test_fn` in this scope - --> ui_tests/second_shared_ref.rs:24:8 - | -24 | if test_fn(n, &true) { - | ^^^^^^^ not found in this scope diff --git a/src/eval/eval_context.rs b/src/eval/eval_context.rs index 5152938dc..1ac44b6e4 100644 --- a/src/eval/eval_context.rs +++ b/src/eval/eval_context.rs @@ -5,12 +5,16 @@ use crate::ast::FnCallHashes; use crate::tokenizer::{is_valid_function_name, Token}; use crate::types::dynamic::Variant; use crate::{ - calc_fn_hash, expose_under_internals, Dynamic, Engine, FnArgsVec, FuncArgs, Position, - RhaiResult, RhaiResultOf, Scope, StaticVec, ERR, + calc_fn_hash, expose_under_internals, Dynamic, Engine, FnArgsVec, FuncArgs, ImmutableString, + Position, RhaiResult, RhaiResultOf, Scope, StaticVec, ERR, }; -use std::any::type_name; #[cfg(feature = "no_std")] use std::prelude::v1::*; +use std::{ + any::type_name, + mem, + ops::{Deref, DerefMut}, +}; /// Context of a script evaluation process. #[allow(dead_code)] @@ -59,6 +63,13 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> { pub fn source(&self) -> Option<&str> { self.global.source() } + /// Get a mutable reference to the current source. + #[inline(always)] + #[must_use] + pub fn source_mut(&mut self) -> &mut Option { + &mut self.global.source + } + /// The current [`Scope`]. #[inline(always)] #[must_use] @@ -141,6 +152,24 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> { pub const fn call_level(&self) -> usize { self.global.level } + /// _(internals, debugging)_ Debugging interface. + /// Exported under the `debugging` and `internals` features only. + #[cfg(feature = "debugging")] + #[cfg(feature = "internals")] + #[inline(always)] + #[must_use] + pub fn debugger(&self) -> Option<&crate::debugger::Debugger> { + self.global.debugger.as_deref() + } + /// _(internals, debugging)_ Mutable reference to the debugging interface. + /// Exported under the `debugging` and `internals` features only. + #[cfg(feature = "debugging")] + #[cfg(feature = "internals")] + #[inline(always)] + #[must_use] + pub fn debugger_mut(&mut self) -> Option<&mut crate::debugger::Debugger> { + self.global.debugger.as_deref_mut() + } /// Evaluate an [expression tree][crate::Expression] within this [evaluation context][`EvalContext`]. /// @@ -364,6 +393,69 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> { false, ) } + + /// Create a new isolated runtime frame guard, restoring field values upon `Drop`. + /// + /// The [frame guard][EvalContextFrameGuard] returned derefs to [`EvalContext`]. + /// + /// # Examples + /// + /// ```rust,ignore + /// // The following pushes a new, empty, caching layer to make sure that new function resolutions + /// // do not persist. This is useful if the resolution will be volatile. + /// let result: i64 = context.new_frame() + /// .with_new_caching_layer() + /// .call_fn("foo", (0_i64,))?; + /// + /// // In the above example, the resolution to function 'foo' will not be cached outside the frame. + /// // The next call to 'foo' will be resolved again instead of using the cached resolution, + /// // even if 'foo' is redefined. + /// + /// // The following modifies the [`EvalContext`] before using, restoring its state afterwards. + /// { + /// // Modify the context before using... + /// let context = context.new_frame() + /// .rewind_scope(true) // rewinds the scope... + /// .with_source("new source") // new source... + /// .with_module(new_module) // add new module... + /// .up_call_level(); + /// + /// // Call a function with the modified context... + /// let result: i64 = context.call_fn("foo", (0_i64,))?; + /// + /// // ... at end of block, context automatically restored to previous state. + /// } + /// ``` + /// + /// ## `Drop` behavior + /// + /// Upon `Drop`, the following fields will be automatically restored to the previous values: + /// + /// * the stack of imported [modules][crate::Module] will be rewound to the original depth if more [modules][crate::Module] have been added via [`EvalContextFrameGuard::with_import`]. + /// * the stack of global [modules][crate::Module] will be rewound to the original depth if more [modules][crate::Module] have been added via [`EvalContextFrameGuard::with_module`]. + /// * the original functions resolution cache will be restored if a new caching layer was created via [`EvalContextFrameGuard::with_new_caching_layer`]. + /// * the original [scope][EvalContext::scope] will be rewound if [`EvalContextFrameGuard::rewind_scope`] was set to `true`. + /// * the [source][GlobalRuntimeState::source] will be restored if a new source was set via [`EvalContextFrameGuard::with_source`] or cleared via [`EvalContextFrameGuard::clear_source`]. + /// * the current [nesting level][GlobalRuntimeState::level] of function calls will be restored if modified via [`EvalContextFrameGuard::up_call_level`]. + /// * the current [`tag`][GlobalRuntimeState::tag] will be restored if modified via [`EvalContextFrameGuard::with_tag`] or [`EvalContextFrameGuard::clear_tag`]. + pub fn new_frame<'f>(&'f mut self) -> EvalContextFrameGuard<'f, 'a, 's, 'ps, 'g, 'c, 't> { + EvalContextFrameGuard { + #[cfg(feature = "internals")] + #[cfg(not(feature = "no_module"))] + imports_len: None, + #[cfg(feature = "internals")] + #[cfg(not(feature = "no_function"))] + lib_len: None, + caches_len: None, + scope_len: None, + source: None, + #[cfg(feature = "internals")] + level: None, + tag: None, + + context: self, + } + } } /// Call a function (native Rust or scripted) inside the [evaluation context][`EvalContext`]. @@ -431,3 +523,153 @@ fn _call_fn_raw( ) .map(|(r, ..)| r) } + +/// A new frame guard for [`EvalContext`], restoring field values upon `Drop`. +pub struct EvalContextFrameGuard<'f, 'a, 's, 'ps, 'g, 'c, 't> { + context: &'f mut EvalContext<'a, 's, 'ps, 'g, 'c, 't>, + + caches_len: Option, + scope_len: Option, + #[cfg(feature = "internals")] + #[cfg(not(feature = "no_module"))] + imports_len: Option, + #[cfg(feature = "internals")] + #[cfg(not(feature = "no_function"))] + lib_len: Option, + source: Option>, + #[cfg(feature = "internals")] + level: Option, + tag: Option, +} + +impl Drop for EvalContextFrameGuard<'_, '_, '_, '_, '_, '_, '_> { + #[inline(always)] + fn drop(&mut self) { + if let Some(caches_len) = self.caches_len { + self.context.caches.rewind_fn_resolution_caches(caches_len); + } + if let Some(scope_len) = self.scope_len { + self.context.scope.rewind(scope_len); + } + #[cfg(feature = "internals")] + #[cfg(not(feature = "no_module"))] + if let Some(imports_len) = self.imports_len { + self.context.global.truncate_imports(imports_len); + } + #[cfg(feature = "internals")] + #[cfg(not(feature = "no_function"))] + if let Some(lib_len) = self.lib_len { + self.context.global.lib.truncate(lib_len); + } + if let Some(source) = self.source.take() { + *self.context.source_mut() = source; + } + #[cfg(feature = "internals")] + if let Some(level) = self.level { + self.context.global.level = level; + } + if let Some(tag) = self.tag.take() { + *self.context.tag_mut() = tag; + } + } +} + +impl<'a, 's, 'ps, 'g, 'c, 't> Deref for EvalContextFrameGuard<'_, 'a, 's, 'ps, 'g, 'c, 't> { + type Target = EvalContext<'a, 's, 'ps, 'g, 'c, 't>; + + #[inline(always)] + fn deref(&self) -> &Self::Target { + self.context + } +} + +impl<'a, 's, 'ps, 'g, 'c, 't> DerefMut for EvalContextFrameGuard<'_, 'a, 's, 'ps, 'g, 'c, 't> { + #[inline(always)] + fn deref_mut(&mut self) -> &mut Self::Target { + self.context + } +} + +impl<'t> EvalContextFrameGuard<'_, '_, '_, '_, '_, '_, 't> { + /// Push a new caching layer for function resolution results. + pub fn with_new_caching_layer(mut self) -> Self { + self.caches_len = Some(self.context.caches.fn_resolution_caches_len()); + self.context.caches.push_fn_resolution_cache(); + self + } + /// Rewind the [scope][EvalContext::scope]. + #[inline(always)] + pub fn rewind_scope(mut self, enable: bool) -> Self { + self.scope_len = if enable { + Some(self.context.scope().len()) + } else { + None + }; + self + } + /// Modify the current source. + #[inline(always)] + pub fn with_source(mut self, source: impl Into) -> Self { + self.source = Some(Some(source.into())); + mem::swap(self.context.source_mut(), self.source.as_mut().unwrap()); + self + } + /// Clear the current source. + #[inline(always)] + pub fn clear_source(mut self) -> Self { + self.source = Some(None); + mem::swap(self.context.source_mut(), self.source.as_mut().unwrap()); + self + } + /// Modify the custom state. + #[inline(always)] + pub fn with_tag(mut self, tag: Dynamic) -> Self { + self.tag = Some(tag); + mem::swap(self.context.tag_mut(), self.tag.as_mut().unwrap()); + self + } + /// Modify the custom state to [`Dynamic::UNIT`]. + #[inline(always)] + pub fn clear_tag(mut self) -> Self { + self.tag = Some(Dynamic::UNIT); + mem::swap(self.context.tag_mut(), self.tag.as_mut().unwrap()); + self + } + /// _(internals)_ Add a new imported [module][crate::Module]. + /// Exported under the `internals` feature only. + /// + /// Not available under `no_module`. + #[cfg(feature = "internals")] + #[cfg(not(feature = "no_module"))] + pub fn with_import( + mut self, + name: impl Into, + module: impl Into, + ) -> Self { + self.imports_len = Some(self.context.global.num_imports()); + self.context.global.push_import(name.into(), module.into()); + self + } + /// _(internals)_ Add a new [module][crate::Module] containing script-defined functions. + /// Exported under the `internals` feature only. + /// + /// Not available under `no_function`. + #[cfg(feature = "internals")] + #[cfg(not(feature = "no_function"))] + #[inline(always)] + #[must_use] + pub fn with_module(mut self, module: impl Into) -> Self { + self.lib_len = Some(self.context.global.lib.len()); + self.context.global.lib.push(module.into()); + self + } + /// _(internals)_ Increment the current nesting level of function calls. + /// Exported under the `internals` feature only. + #[cfg(feature = "internals")] + #[inline(always)] + pub fn up_call_level(mut self) -> Self { + self.level = Some(self.context.global.level); + self.context.global.level += 1; + self + } +} diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 753ad4f89..8dde7b559 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -25,7 +25,7 @@ pub use debugger::{ BreakPoint, Debugger, DebuggerCommand, DebuggerEvent, DebuggerStatus, OnDebuggerCallback, OnDebuggingInit, }; -pub use eval_context::EvalContext; +pub use eval_context::{EvalContext, EvalContextFrameGuard}; pub use global_state::GlobalRuntimeState; #[cfg(not(feature = "no_module"))] diff --git a/src/func/native.rs b/src/func/native.rs index 2a1dd01d7..559acac27 100644 --- a/src/func/native.rs +++ b/src/func/native.rs @@ -265,16 +265,6 @@ impl<'a> NativeCallContext<'a> { pub fn iter_imports(&self) -> impl Iterator { self.global.iter_imports() } - /// _(internals)_ The current [`GlobalRuntimeState`], if any. - /// Exported under the `internals` feature only. - /// - /// Not available under `no_module`. - #[expose_under_internals] - #[inline(always)] - #[must_use] - const fn global_runtime_state(&self) -> &GlobalRuntimeState { - self.global - } /// Get an iterator over the namespaces containing definitions of all script-defined functions /// in reverse order (i.e. parent namespaces are iterated after child namespaces). /// @@ -295,6 +285,25 @@ impl<'a> NativeCallContext<'a> { pub fn namespaces(&self) -> &[crate::SharedModule] { &self.global.lib } + /// _(internals)_ The current [`GlobalRuntimeState`], if any. + /// Exported under the `internals` feature only. + /// + /// Not available under `no_module`. + #[expose_under_internals] + #[inline(always)] + #[must_use] + const fn global_runtime_state(&self) -> &GlobalRuntimeState { + self.global + } + /// _(internals, debugging)_ Debugging interface. + /// Exported under the `debugging` and `internals` features only. + #[cfg(feature = "debugging")] + #[cfg(feature = "internals")] + #[inline(always)] + #[must_use] + pub fn debugger(&self) -> Option<&crate::debugger::Debugger> { + self.global.debugger.as_deref() + } /// Call a function inside the call context with the provided arguments. #[inline] diff --git a/src/lib.rs b/src/lib.rs index 97cb36af9..e40ea3748 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -229,7 +229,7 @@ pub use api::{eval::eval, run::run}; pub use ast::{FnAccess, AST}; use defer::Deferred; pub use engine::{Engine, OP_CONTAINS, OP_EQUALS}; -pub use eval::EvalContext; +pub use eval::{EvalContext, EvalContextFrameGuard}; #[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_object"))] use func::calc_typed_method_hash; diff --git a/tests/functions.rs b/tests/functions.rs index 4e7e39194..0359e566b 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -626,9 +626,8 @@ fn test_missing_function_receives_args() { #[cfg(not(feature = "no_object"))] fn test_missing_function_not_called_for_existing() { use std::sync::atomic::{AtomicBool, Ordering}; - use std::sync::Arc; - let called = Arc::new(AtomicBool::new(false)); + let called = Shared::new(AtomicBool::new(false)); let called_clone = called.clone(); let mut engine = Engine::new(); @@ -708,9 +707,8 @@ fn test_missing_function_multiple_arities() { #[cfg(not(feature = "no_object"))] fn test_missing_function_is_method_call_flag() { use std::sync::atomic::{AtomicBool, Ordering}; - use std::sync::Arc; - let saw_method = Arc::new(AtomicBool::new(false)); + let saw_method = Shared::new(AtomicBool::new(false)); let saw_method_clone = saw_method.clone(); let mut engine = Engine::new();