Hi, I am trying to use a procedural macro as a custom inner attribute, I have added this code to the top of main.rs, my crate root-
#![feature(custom_inner_attributes)]
#![my_macro_crate::my_macro]
// my code
...
I am getting 4 errors with cargo +nightly run.
error: expected square brackets
--> src/main.rs:1:1
error: #[panic_handler] function required but not found
error: main function not found
So, I definitely have a main function, I am just wondering what else I need to do to get this to compile correctly so I can use custom inner attributes.
Can someone help me get this working or point me to a guide that does this?
Hey, I tried cargo +nightly expand > output.rs, and this only outputs #![feature(prelude_import)] into output.rs, but it only gives me one error: "expected square brackets", again at 1:1. Maybe it is also useful to say that it has red highlights at the end of the file too for this error.
Also, when I use a more basic procedural macro which is a no-op, cargo +nightly run fails and says #[prelude_import] is for use by rustc only. How does a no-op macro fail?
I think the fact #[prelude_import] even is present is an indicator maybe the macro expansion happened (at least part of it) at different phase in the compiler pipeline than "regular" procedural macros, and given the highly experimental nature of #![feature(custom_inner_attributes)], I'm not supprised it shows quirky errors like this.
curiously, using procedural macros as custom inner attributes is pretty much a "self modification code" problem, except it's not about machine code, but source code.
it can be especially tricky when applied at the crate root, since it can mess with compiler "built-in" transformations for the root module, and I think the prelude_import error is likely one example of such cases.
that's probably why cargo expand won't help, since it expands macros recusrively (iteratively?) until it converges or certain limits are reached. what would be better to help understand the problem is a command to expand a macro one single step a time, but I don't know any such tool exists.
Seeing some of the problems with this unstable feature, it's not too surprising. I hope it'll be available at some point. EDIT: Oh, but I've already given you that link, sorry.