JohnTitor / ctest2

Automatic testing of FFI bindings for Rust
https://crates.io/crates/ctest2
Apache License 2.0
22 stars 20 forks source link

Can't parse macro-processed extern "C" block #36

Open joshtriplett opened 2 years ago

joshtriplett commented 2 years ago

Given a macro which processes extern C functions:

macro_rules! some_macro {
    (extern "C" { $($i:item)* }) => ( extern "C" { $($i)* });
}

And code invoking it:

some_macro! {
    extern "C" {
        pub fn func(arg: c_int) -> c_int;
    }
}

systest will fail to parse this, emitting an error like this:

  error: expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found `;`
     --> ../src/lib.rs:120:82
      |
  118 | / some_macro! {
  119 | |     extern "C" {
  120 | |         pub fn func(arg: c_int) -> c_int;
      | |                                         ^ expected one of `!`, `(`, `::`, `<`, `where`, or `{` here

If I modify the macro and invocation to go inside the extern "C" block rather than outside it, I instead get an internal compiler error:

  error: internal compiler error: Error constructed but not emitted

  thread 'main' panicked at 'explicit panic', /path/to/.cargo/registry/src/github.com-1ecc6299db9ec823/garando_errors-0.1.0/src/diagnostic_builder.rs:190:13
JohnTitor commented 2 years ago

I think this has the same root cause as #6, i.e. our parsing libraries are too old. We have to migrate to a newer crate (e.g. syn?) but it'd be hard work and I cannot promise I will work on it soon.