Repository: rust
Issue: `include!()` code inside of a decl macro cannot access identifiers declared within the macro
Labels: A-macros,C-bug

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

Related issue: https://github.com/rust-sailfish/sailfish/issues/59#issuecomment-1833296032


Please test with the [crate source code](https://github.com/rust-sailfish/sailfish).
Test once with the original code, it works well.

And then modify the file `examples/simple.rs` as:
```rust
use sailfish::TemplateOnce;

macro_rules! template {
    ($name:ident, $path:literal, { $($field:ident: $type:ty),* } ) => {
        #[derive(TemplateOnce)]
        #[template(path=$path)]
        struct $name {
            $($field: $type,)*
        }
    }
}

template!(Simple, "simple.stpl", { messages: Vec<String> });

fn main() {
    let messages = vec![String::from("Message 1"), String::from("<Message 2>")];
    println!("{}", Simple { messages }.render_once().unwrap();
}
```

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
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.74.0 (79e9716c9 2023-11-13)
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
Running `cargo +nightly run -p sailfish-examples --bin simple --message-format=json`...
   Compiling sailfish-compiler v0.8.3 (E:\Codes\Source\sailfish\sailfish-compiler)
   Compiling sailfish-macros v0.8.3 (E:\Codes\Source\sailfish\sailfish-macros)
   Compiling sailfish v0.8.3 (E:\Codes\Source\sailfish\sailfish)
   Compiling sailfish-examples v0.8.3 (E:\Codes\Source\sailfish\examples)
error[E0425]: cannot find value `__sf_buf` in this scope
 --> e:\Codes\Source\sailfish\target\debug\build\sailfish-compiler-6296a0e0a31320dd\out\templates\ac48a56bd5e90428-4d1386660dfbab60:2:29
  |
2 | { __sf_rt :: render_text ! (__sf_buf , "<!DOCTYPE html>\n<html>\n  <body>\n    \n    ") ; for (i , msg) in messages . iter () . enumerate...
  |                             ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__sf_buf` in this scope
 --> e:\Codes\Source\sailfish\target\debug\build\sailfish-compiler-6296a0e0a31320dd\out\templates\ac48a56bd5e90428-4d1386660dfbab60:2:170
  |
2 | ...iter () . enumerate () { __sf_rt :: render_text ! (__sf_buf , "\n      ") ; if i == 0 { __sf_rt :: render_text ! (__sf_buf , "\n      ...
  |                                                       ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__sf_buf` in this scope
 --> e:\Codes\Source\sailfish\target\debug\build\sailfish-compiler-6296a0e0a31320dd\out\templates\ac48a56bd5e90428-4d1386660dfbab60:2:233
  |
2 | ...\n      ") ; if i == 0 { __sf_rt :: render_text ! (__sf_buf , "\n        <h1>Hello, world!</h1>\n      ") ; } __sf_rt :: render_text !...
  |                                                       ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__sf_buf` in this scope
 --> e:\Codes\Source\sailfish\target\debug\build\sailfish-compiler-6296a0e0a31320dd\out\templates\ac48a56bd5e90428-4d1386660dfbab60:2:318
  |
2 | ...orld!</h1>\n      ") ; } __sf_rt :: render_text ! (__sf_buf , "\n      <div>") ; __sf_rt :: render_escaped ! (__sf_buf , * msg) ; __sf...
  |                                                       ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__sf_buf` in this scope
 --> e:\Codes\Source\sailfish\target\debug\build\sailfish-compiler-6296a0e0a31320dd\out\templates\ac48a56bd5e90428-4d1386660dfbab60:2:377
  |
2 | ... , "\n      <div>") ; __sf_rt :: render_escaped ! (__sf_buf , * msg) ; __sf_rt :: render_text ! (__sf_buf , "</div>\n    ") ; } __sf_r...
  |                                                       ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__sf_buf` in this scope
 --> e:\Codes\Source\sailfish\target\debug\build\sailfish-compiler-6296a0e0a31320dd\out\templates\ac48a56bd5e90428-4d1386660dfbab60:2:423
  |
2 | ...d ! (__sf_buf , * msg) ; __sf_rt :: render_text ! (__sf_buf , "</div>\n    ") ; } __sf_rt :: render_text ! (__sf_buf , "\n  </body>\n<...
  |                                                       ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__sf_buf` in this scope
 --> e:\Codes\Source\sailfish\target\debug\build\sailfish-compiler-6296a0e0a31320dd\out\templates\ac48a56bd5e90428-4d1386660dfbab60:2:480
  |
2 | ...uf , "</div>\n    ") ; } __sf_rt :: render_text ! (__sf_buf , "\n  </body>\n</html>") ; }
  |                                                       ^^^^^^^^ not found in this scope

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0425`.
error: could not compile `sailfish-examples` (bin "simple") due to 8 previous errors
Error: Cargo invocation failed.
        at t.Cargo.getCargoArtifacts (c:\Users\Sling\.vscode\extensions\vadimcn.vscode-lldb-1.10.0\extension.js:1:14943)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Object.open (c:\Users\Sling\.vscode\extensions\vadimcn.vscode-lldb-1.10.0\extension.js:1:13253)
Caused by: Error: exit code: 101.
        at ChildProcess.<anonymous> (c:\Users\Sling\.vscode\extensions\vadimcn.vscode-lldb-1.10.0\extension.js:1:16610)
        at ChildProcess.emit (node:events:513:28)
        at ChildProcess.emit (node:domain:489:12)
        at maybeClose (node:internal/child_process:1091:16)
        at ChildProcess._handle.onexit (node:internal/child_process:302:5)
 *  The terminal process terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 
```

</p>
</details>

Seems after **using macro_rules**, the `include!()`;  cannot get the `current scope variable "__sf_buf"`.
The root code is here: https://github.com/rust-sailfish/sailfish/blob/2e392994830084874b2695bf7953f245752d7d44/sailfish-compiler/src/procmacro.rs#L374