-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
include!()
code inside of a decl macro cannot access identifiers declared within the macro
#118475
Comments
Given a template file containing something like "test", sailfish will generate a file like this {
__sf_rt::render_text!(__sf_buf, "test");
} The derive macro will then use this like so: quote! {
/* ... */
fn render_once_to(self, __sf_buf: &mut sailfish::runtime::Buffer) -> std::result::Result<(), sailfish::runtime::RenderError> {
// This line is required for cargo to track child templates
#include_bytes_seq;
use sailfish::runtime as __sf_rt;
let #name { #field_names } = self;
include!(#output_file_string);
Ok(())
}
/* ... */
} Given that We can also access global identifers |
include!
'd code inside of a decl macro cannot access identifiers declared within the macro
include!
'd code inside of a decl macro cannot access identifiers declared within the macroincluded!()
code inside of a decl macro cannot access identifiers declared within the macro
included!()
code inside of a decl macro cannot access identifiers declared within the macroinclude!()
code inside of a decl macro cannot access identifiers declared within the macro
@clubby789 Sure, thanks for your assistance. 😉 The code bellow throws the error as well. macro_rules! generate {
() => {
fn log() {
let num = 2;
include!("./file.txt");
}
};
}
generate!();
fn main() {
log();
}
{
num
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related issue: rust-sailfish/sailfish#59 (comment)
Please test with the crate source code.
Test once with the original code, it works well.
And then modify the file
examples/simple.rs
as:It will throw errors. The built codes between these two operations are TOTTALY the SAME.
So I guess it maybe is caused by the rustc compiler.
Meta
rustc --version --verbose
:Backtrace
Seems after using macro_rules, the
include!()
; cannot get thecurrent scope variable "__sf_buf"
.The root code is here: https://github.com/rust-sailfish/sailfish/blob/2e392994830084874b2695bf7953f245752d7d44/sailfish-compiler/src/procmacro.rs#L374
The text was updated successfully, but these errors were encountered: