Failed to compile the demo procedural macros


#1

I followed the tutorial on Procedual Macro, and I am using the Rust version 1.15 (also I tested nightly 1.16). However when I use cargo build to build the hello-world project, it failed with information:

error: invalid format string: expected `'}'`, found `']'`
  --> src/main.rs:17:1
   |
17 | #[derive(HelloWorld)]
   | ^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro outside of the current crate

error: aborting due to previous error

error: Could not compile `hello-world`.

The source code are presented in git@github.com:qorost/procedural-macro-demo.git


#2

You have:

println!("Hello, world , my name is {]",stringify!(#name) );

It should be {} in the format string.


#3

What a stupid error!

Thanks @cuviper for helping me out.

I was focusing on the hello-world module. It was interesting when I compile the hello-world-derive, it succeeded without errors.


#4

Yes, code generation is tricky like that, and the error doesn’t do a good job of tracing the true origin, just “outside the current crate”. The quote! is what let this code compile fine into hello-world-derive, because it wasn’t actually doing anything yet.


#5

Thanks for your detailed explanation, it really clarifies me.