New Procedural Macros Crate v0.1
This commit is contained in:
22
codegen/ui_tests/first_shared_ref.rs
Normal file
22
codegen/ui_tests/first_shared_ref.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use rhai::export_fn;
|
||||
|
||||
struct NonClonable {
|
||||
a: f32,
|
||||
b: u32,
|
||||
c: char,
|
||||
d: bool,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
pub fn test_fn(input: &NonClonable) -> bool {
|
||||
input.d
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n = NonClonable { a: 0.0, b: 10, c: 'a', d: true };
|
||||
if test_fn(n) {
|
||||
println!("yes");
|
||||
} else {
|
||||
println!("no");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/first_shared_ref.stderr
Normal file
11
codegen/ui_tests/first_shared_ref.stderr
Normal file
@@ -0,0 +1,11 @@
|
||||
error: references from Rhai in this position must be mutable
|
||||
--> $DIR/first_shared_ref.rs:11:23
|
||||
|
|
||||
11 | pub fn test_fn(input: &NonClonable) -> bool {
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `test_fn` in this scope
|
||||
--> $DIR/first_shared_ref.rs:17:8
|
||||
|
|
||||
17 | if test_fn(n) {
|
||||
| ^^^^^^^ not found in this scope
|
22
codegen/ui_tests/non_clonable.rs
Normal file
22
codegen/ui_tests/non_clonable.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use rhai::export_fn;
|
||||
|
||||
struct NonClonable {
|
||||
a: f32,
|
||||
b: u32,
|
||||
c: char,
|
||||
d: bool,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
pub fn test_fn(input: NonClonable) -> bool {
|
||||
input.d
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n = NonClonable { a: 0.0, b: 10, c: 'a', d: true };
|
||||
if test_fn(n) {
|
||||
println!("yes");
|
||||
} else {
|
||||
println!("no");
|
||||
}
|
||||
}
|
5
codegen/ui_tests/non_clonable.stderr
Normal file
5
codegen/ui_tests/non_clonable.stderr
Normal file
@@ -0,0 +1,5 @@
|
||||
error[E0277]: the trait bound `NonClonable: std::clone::Clone` is not satisfied
|
||||
--> $DIR/non_clonable.rs:11:23
|
||||
|
|
||||
11 | pub fn test_fn(input: NonClonable) -> bool {
|
||||
| ^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `NonClonable`
|
22
codegen/ui_tests/non_clonable_second.rs
Normal file
22
codegen/ui_tests/non_clonable_second.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use rhai::export_fn;
|
||||
|
||||
struct NonClonable {
|
||||
a: f32,
|
||||
b: u32,
|
||||
c: char,
|
||||
d: bool,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
pub fn test_fn(a: u32, b: NonClonable) -> bool {
|
||||
a == 0 && b.d
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n = NonClonable { a: 0.0, b: 10, c: 'a', d: true };
|
||||
if test_fn(10, n) {
|
||||
println!("yes");
|
||||
} else {
|
||||
println!("no");
|
||||
}
|
||||
}
|
5
codegen/ui_tests/non_clonable_second.stderr
Normal file
5
codegen/ui_tests/non_clonable_second.stderr
Normal file
@@ -0,0 +1,5 @@
|
||||
error[E0277]: the trait bound `NonClonable: std::clone::Clone` is not satisfied
|
||||
--> $DIR/non_clonable_second.rs:11:27
|
||||
|
|
||||
11 | pub fn test_fn(a: u32, b: NonClonable) -> bool {
|
||||
| ^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `NonClonable`
|
23
codegen/ui_tests/return_mut_ref.rs
Normal file
23
codegen/ui_tests/return_mut_ref.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use rhai::export_fn;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Clonable {
|
||||
a: f32,
|
||||
b: u32,
|
||||
c: char,
|
||||
d: bool,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
pub fn test_fn(input: &mut Clonable) -> &mut bool {
|
||||
&mut input.d
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n = Clonable { a: 0.0, b: 10, c: 'a', d: true };
|
||||
if test_fn(n) {
|
||||
println!("yes");
|
||||
} else {
|
||||
println!("no");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/return_mut_ref.stderr
Normal file
11
codegen/ui_tests/return_mut_ref.stderr
Normal file
@@ -0,0 +1,11 @@
|
||||
error: cannot return a reference to Rhai
|
||||
--> $DIR/return_mut_ref.rs:12:38
|
||||
|
|
||||
12 | pub fn test_fn(input: &mut Clonable) -> &mut bool {
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `test_fn` in this scope
|
||||
--> $DIR/return_mut_ref.rs:18:8
|
||||
|
|
||||
18 | if test_fn(n) {
|
||||
| ^^^^^^^ not found in this scope
|
19
codegen/ui_tests/return_pointer.rs
Normal file
19
codegen/ui_tests/return_pointer.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use rhai::export_fn;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Clonable {
|
||||
a: f32,
|
||||
b: u32,
|
||||
c: char,
|
||||
d: bool,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
pub fn test_fn(input: Clonable) -> *const str {
|
||||
"yes"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n = Clonable { a: 0.0, b: 10, c: 'a', d: true };
|
||||
println!("{}", unsafe { let ptr = test_fn(n); *ptr });
|
||||
}
|
11
codegen/ui_tests/return_pointer.stderr
Normal file
11
codegen/ui_tests/return_pointer.stderr
Normal file
@@ -0,0 +1,11 @@
|
||||
error: cannot return a pointer to Rhai
|
||||
--> $DIR/return_pointer.rs:12:33
|
||||
|
|
||||
12 | pub fn test_fn(input: Clonable) -> *const str {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `test_fn` in this scope
|
||||
--> $DIR/return_pointer.rs:18:39
|
||||
|
|
||||
18 | println!("{}", unsafe { let ptr = test_fn(n); *ptr });
|
||||
| ^^^^^^^ not found in this scope
|
19
codegen/ui_tests/return_shared_ref.rs
Normal file
19
codegen/ui_tests/return_shared_ref.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use rhai::export_fn;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Clonable {
|
||||
a: f32,
|
||||
b: u32,
|
||||
c: char,
|
||||
d: bool,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
pub fn test_fn(input: Clonable) -> & 'static str {
|
||||
"yes"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n = Clonable { a: 0.0, b: 10, c: 'a', d: true };
|
||||
println!("{}", test_fn(n));
|
||||
}
|
11
codegen/ui_tests/return_shared_ref.stderr
Normal file
11
codegen/ui_tests/return_shared_ref.stderr
Normal file
@@ -0,0 +1,11 @@
|
||||
error: cannot return a reference to Rhai
|
||||
--> $DIR/return_shared_ref.rs:12:33
|
||||
|
|
||||
12 | pub fn test_fn(input: Clonable) -> & 'static str {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `test_fn` in this scope
|
||||
--> $DIR/return_shared_ref.rs:18:20
|
||||
|
|
||||
18 | println!("{}", test_fn(n));
|
||||
| ^^^^^^^ not found in this scope
|
23
codegen/ui_tests/second_shared_ref.rs
Normal file
23
codegen/ui_tests/second_shared_ref.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use rhai::export_fn;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Clonable {
|
||||
a: f32,
|
||||
b: u32,
|
||||
c: char,
|
||||
d: bool,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
pub fn test_fn(input: Clonable, factor: &bool) -> bool {
|
||||
input.d & factor
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n = Clonable { a: 0.0, b: 10, c: 'a', d: true };
|
||||
if test_fn(n, &true) {
|
||||
println!("yes");
|
||||
} else {
|
||||
println!("no");
|
||||
}
|
||||
}
|
11
codegen/ui_tests/second_shared_ref.stderr
Normal file
11
codegen/ui_tests/second_shared_ref.stderr
Normal file
@@ -0,0 +1,11 @@
|
||||
error: this type in this position passes from Rhai by value
|
||||
--> $DIR/second_shared_ref.rs:12:41
|
||||
|
|
||||
12 | pub fn test_fn(input: Clonable, factor: &bool) -> bool {
|
||||
| ^^^^^
|
||||
|
||||
error[E0425]: cannot find function `test_fn` in this scope
|
||||
--> $DIR/second_shared_ref.rs:18:8
|
||||
|
|
||||
18 | if test_fn(n, &true) {
|
||||
| ^^^^^^^ not found in this scope
|
Reference in New Issue
Block a user