From 6546eae95fee0dffadfcea9aa61ca8766b3f4be0 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 18 Mar 2022 17:51:04 +0800 Subject: [PATCH] Fix macro hygene. --- codegen/src/function.rs | 8 +++++--- codegen/ui_tests/export_fn_raw_return.stderr | 3 +++ codegen/ui_tests/export_mod_raw_return.stderr | 4 ++++ codegen/ui_tests/rhai_fn_non_clonable_return.stderr | 10 +++++----- codegen/ui_tests/rhai_mod_non_clonable_return.stderr | 11 ++++++----- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/codegen/src/function.rs b/codegen/src/function.rs index 9bd07eba..e276cfa8 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -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),*))) diff --git a/codegen/ui_tests/export_fn_raw_return.stderr b/codegen/ui_tests/export_fn_raw_return.stderr index 576e999f..629cda62 100644 --- a/codegen/ui_tests/export_fn_raw_return.stderr +++ b/codegen/ui_tests/export_fn_raw_return.stderr @@ -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) diff --git a/codegen/ui_tests/export_mod_raw_return.stderr b/codegen/ui_tests/export_mod_raw_return.stderr index 55e1d185..1464012e 100644 --- a/codegen/ui_tests/export_mod_raw_return.stderr +++ b/codegen/ui_tests/export_mod_raw_return.stderr @@ -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) diff --git a/codegen/ui_tests/rhai_fn_non_clonable_return.stderr b/codegen/ui_tests/rhai_fn_non_clonable_return.stderr index 9d946726..efcd40de 100644 --- a/codegen/ui_tests/rhai_fn_non_clonable_return.stderr +++ b/codegen/ui_tests/rhai_fn_non_clonable_return.stderr @@ -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(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) diff --git a/codegen/ui_tests/rhai_mod_non_clonable_return.stderr b/codegen/ui_tests/rhai_mod_non_clonable_return.stderr index 1d664c65..d96fe2c8 100644 --- a/codegen/ui_tests/rhai_mod_non_clonable_return.stderr +++ b/codegen/ui_tests/rhai_mod_non_clonable_return.stderr @@ -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(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)