Fix macro hygene.

This commit is contained in:
Stephen Chung 2022-03-18 17:51:04 +08:00
parent d01a6d428f
commit 6546eae95f
5 changed files with 23 additions and 13 deletions

View File

@ -651,7 +651,8 @@ impl ExportedFn {
let return_span = self
.return_type()
.map(|r| r.span())
.unwrap_or_else(Span::call_site);
.unwrap_or_else(Span::call_site)
.resolved_at(Span::call_site());
if self.params.return_raw.is_some() {
quote_spanned! { return_span =>
pub #dynamic_signature {
@ -765,7 +766,7 @@ impl ExportedFn {
syn::Type::Path(ref p) if p.path == str_type_path => {
is_string = true;
is_ref = true;
quote_spanned!(arg_type.span() =>
quote_spanned!(arg_type.span().resolved_at(Span::call_site()) =>
mem::take(args[#i]).into_immutable_string().unwrap()
)
}
@ -834,7 +835,8 @@ impl ExportedFn {
let return_span = self
.return_type()
.map(|r| r.span())
.unwrap_or_else(Span::call_site);
.unwrap_or_else(Span::call_site)
.resolved_at(Span::call_site());
let return_expr = if self.params.return_raw.is_none() {
quote_spanned! { return_span =>
Ok(Dynamic::from(#sig_name(#(#unpack_exprs),*)))

View File

@ -1,9 +1,12 @@
error[E0599]: `bool` is not an iterator
--> ui_tests/export_fn_raw_return.rs:10:33
|
9 | #[export_fn(return_raw)]
| ------------------------ in this procedural macro expansion
10 | pub fn test_fn(input: Point) -> bool {
| ^^^^ `bool` is not an iterator
|
= note: the following trait bounds were not satisfied:
`bool: std::iter::Iterator`
which is required by `&mut bool: std::iter::Iterator`
= note: this error originates in the attribute macro `export_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,9 +1,13 @@
error[E0599]: `bool` is not an iterator
--> ui_tests/export_mod_raw_return.rs:12:33
|
9 | #[export_module]
| ---------------- in this procedural macro expansion
...
12 | pub fn test_fn(input: Point) -> bool {
| ^^^^ `bool` is not an iterator
|
= note: the following trait bounds were not satisfied:
`bool: std::iter::Iterator`
which is required by `&mut bool: std::iter::Iterator`
= note: this error originates in the attribute macro `export_module` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,14 +1,14 @@
error[E0277]: the trait bound `NonClonable: Clone` is not satisfied
--> ui_tests/rhai_fn_non_clonable_return.rs:11:8
--> ui_tests/rhai_fn_non_clonable_return.rs:11:31
|
10 | #[export_fn]
| ------------ in this procedural macro expansion
11 | pub fn test_fn(input: f32) -> NonClonable {
| ^^^^^^^^^^^^^^^^^^^^^^^-----------
| | |
| | required by a bound introduced by this call
| the trait `Clone` is not implemented for `NonClonable`
| ^^^^^^^^^^^ the trait `Clone` is not implemented for `NonClonable`
|
note: required by a bound in `rhai::Dynamic::from`
--> $WORKSPACE/src/types/dynamic.rs
|
| pub fn from<T: Variant + Clone>(value: T) -> Self {
| ^^^^^ required by this bound in `rhai::Dynamic::from`
= note: this error originates in the attribute macro `export_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,14 +1,15 @@
error[E0277]: the trait bound `NonClonable: Clone` is not satisfied
--> ui_tests/rhai_mod_non_clonable_return.rs:12:12
--> ui_tests/rhai_mod_non_clonable_return.rs:12:35
|
10 | #[export_module]
| ---------------- in this procedural macro expansion
11 | pub mod test_mod {
12 | pub fn test_fn(input: f32) -> NonClonable {
| ^^^^^^^^^^^^^^^^^^^^^^^-----------
| | |
| | required by a bound introduced by this call
| the trait `Clone` is not implemented for `NonClonable`
| ^^^^^^^^^^^ the trait `Clone` is not implemented for `NonClonable`
|
note: required by a bound in `rhai::Dynamic::from`
--> $WORKSPACE/src/types/dynamic.rs
|
| pub fn from<T: Variant + Clone>(value: T) -> Self {
| ^^^^^ required by this bound in `rhai::Dynamic::from`
= note: this error originates in the attribute macro `export_module` (in Nightly builds, run with -Z macro-backtrace for more info)