0

I got this error when I executed a macro created by proc-macro, my error :

error: proc macro panicked
  --> src/main.rs:16:5
   |
16 |     load_extension_parser!(B);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: use-after-free of `proc_macro` symbol

main.rs

use extension_popper::load_all_extension_parser;
use popper;
use popper::extension::ExtensionParser;
use popper::parser::Parser;
use popper::ast::expr::{Expr, ExprType};

#[extension_parser(B)]
fn a(parser: &mut Parser) -> Expr {
    Expr::new(Box::new(ExprType::Eof), 0..1, String::new())
}



fn main() {
    load_extension_parser!(B);
    B.parse(&mut popper::parser::Parser::new(Vec::new(), String::new()));
}

code of my macro



#[proc_macro_error]
#[proc_macro]
pub fn load_extension_parser(item: TokenStream) -> TokenStream {
    let mut input = parse_macro_input!(item as Ident);
    unsafe {
        if EXTENSIONS.contains(&input) {
            return TokenStream::from(quote! {
                let mut parser = popper::parser::Parser::new();
                parser.add_extension(Box::new(&mut #input));
            })
        } else {
            panic!("Extension not found");
        }
    }

}

I was trying to add an extension to my parser with the macro load_extension_parser but it gives the error

NightProg
  • 1
  • 1
  • 3
  • `use popper;` is useless. – jthulhu Mar 05 '23 at 14:54
  • Looks like a panic originates in the compiler code - https://doc.rust-lang.org/src/proc_macro/bridge/symbol.rs.html#181-190. It will be helpful to get a full self-contained example, not just code snippet (e.g. there's no `EXTENSIONS` defined anywhere now), since it's possible that we should open an issue on Rust repo. – Cerberus Mar 06 '23 at 02:43

0 Answers0