-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent name transformation of pattern matched variables eg: if let Err(...) = ...
#230
Comments
It's because variable is used as argument of macro. Wrap macro with inline
function for the same result.
El dom., 4 jul. 2021 3:47, Guillaume Xavier Taillon <
***@***.***> escribió:
… Hello,
I can work around this issue, but a fix may improve UX for new users.
When attempting to pattern match a Result<>, the compiler complains about
the declared variable not existing.
error[E0425]: cannot find value `e` in this scope
--> src/bin/x.rs:y:z
|123 | .body(auto!(ywrite_min!(String, "{{> pages/query }}"))))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| not found in this scope
| in this macro invocation
|
::: /home/xyz/.cargo/registry/src/github.com-1ecc6299db9ec823/yarte_derive-0.15.4/src/lib.rs:464:1
|464 | pub fn ywrite_min(i: TokenStream) -> TokenStream {
| ------------------------------------------------ in this expansion of procedural macro `ywrite_min!`
Eg:
--------------v
{{#if let Err(e) = feedback }}
<div class="error-message">{{ format!("{}", e) }}</div>
{{/if}}------------------------------------------------^
When looking at the output using cargo-expand (cargo install cargo-expand
&& cargo expand), the declaration has a suffix but the use does not :
[image: image]
<https://user-images.githubusercontent.com/567119/124370531-be180a00-dc46-11eb-86cd-42b05569ac89.png>
Putting the generated suffix in the source template does fix the error.
System versions:
yarte 0.15.4
rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-unknown-linux-gnu
release: 1.53.0
LLVM version: 12.0.1
Best,
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#230>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAUBACM6WTWGGNJ6PLZQCR3TV64T7ANCNFSM47YVZHXQ>
.
|
@gxtaillon Did this solve the problem? Any questions? Close? |
I'm not sure where I'd put an inline function. Do you have an handlebar example of what you're describing? |
Like, #[inline]
fn format<D: std::fmt::Display>(e: D) -> String {
format!("{}", e)
} In template {{ format(bar) }} Remember import |
The body of macros is not transpiled. You can use a function with the inline attribute. There is a bug #211 related to the Span of proc_macro2. If you want transpilation in the body of the macros you can create an issue with the implementation proposal on yarte_lexer. |
Hello,
I can work around this issue, but a fix may improve UX for new users.
When attempting to pattern match a Result<>, the compiler complains about the declared variable not existing.
Eg:
When looking at the output using cargo-expand (
cargo install cargo-expand && cargo expand
), the declaration has a suffix but the use does not :Putting the generated suffix in the source template does fix the error.
System versions:
Best,
The text was updated successfully, but these errors were encountered: