Repository: immunant/c2rust (language: rust)

Issue:
thread 'main' panicked at 'unsupported proc macro punctuation character '(''
Even with qsort example
```
mkdir ../build
cd ../build
cmake ../qsort -DCMAKE_EXPORT_COMPILE_COMMANDS=1
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/krakotay/Documents/c2rust/examples/build
cmake --build .
[ 50%] Building C object CMakeFiles/Qsort.dir/qsort.c.o
[100%] Linking C static library libQsort.a
[100%] Built target Qsort
c2rust transpile compile_commands.json
Transpiling qsort.c
thread 'main' panicked at 'unsupported proc macro punctuation character '('', /home/krakotay/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.87/src/lib.rs:847:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
And with every other project
```
krakotay@1 ~/D/c/e/build (master) [101]> c2rust --version
C2Rust 0.19.0
```
I installed with this command
`cargo install --git https://github.com/immunant/c2rust.git c2rust`
```
krakotay@1 ~/D/c/e/build (master)> screenfetch
                                       krakotay@1
 MMMMMMMMMMMMMMMMMMMMMMMMMmds+.        OS: Linuxmint 22 wilma
 MMm----::-://////////////oymNMd+`     Kernel: x86_64 Linux 6.8.0-38-generic
 MMd      /++                -sNMd:    Uptime: 8m
 MMNso/`  dMM    `.::-. .-::.` .hMN:   Packages: 1927
 ddddMMh  dMM   :hNMNMNhNMNMNh: `NMm   Shell: fish 3.7.0
     NMm  dMM  .NMN/-+MMM+-/NMN` dMM   Disk: 21G / 118G (19%)
     NMm  dMM  -MMm  `MMM   dMM. dMM   CPU: Genuine Intel 0000 @ 8x 3,11GHz
     NMm  dMM  -MMm  `MMM   dMM. dMM   GPU: VMware SVGA II Adapter
     NMm  dMM  .mmd  `mmm   yMM. dMM   RAM: 1183MiB / 7894MiB
     NMm  dMM`  ..`   ...   ydm. dMM
     hMM- +MMd/-------...-:sdds  dMM
     -NMm- :hNMNNNmdddddddddy/`  dMM
      -dMNs-``-::::-------.``    dMM
       `/dMNmy+/:-------------:/yMMM
          ./ydNMMMMMMMMMMMMMMMMMMMMM
             \.MMMMMMMMMMMMMMMMMMM

krakotay@1 ~/D/c/e/build (master)>
```



Discussion / hints:
Full output it
```
krakotay@1 ~/D/c/e/build (master) [101]> c2rust transpile compile_commands.json
Transpiling qsort.c
thread 'main' panicked at 'unsupported proc macro punctuation character '('', /home/krakotay/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.87/src/lib.rs:847:13
stack backtrace:
   0:     0x653a8d3baeaa - std::backtrace_rs::backtrace::libunwind::trace::h9a6b80bbf328ba5d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x653a8d3baeaa - std::backtrace_rs::backtrace::trace_unsynchronized::hd162ec543a11886b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x653a8d3baeaa - std::sys_common::backtrace::_print_fmt::h78a5099be12f51a6
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x653a8d3baeaa - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha1c5390454d74f71
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x653a8d3df3ff - core::fmt::write::h9ffde816c577717b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
   5:     0x653a8d3b78c5 - std::io::Write::write_fmt::h88186074961638e4
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
   6:     0x653a8d3bac75 - std::sys_common::backtrace::_print::h184198273ed08d59
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x653a8d3bac75 - std::sys_common::backtrace::print::h1b4d8e7add699453
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x653a8d3bc1fe - std::panicking::default_hook::{{closure}}::h393bcea75423915a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
   9:     0x653a8d3bbfa5 - std::panicking::default_hook::h48c64f31d8b3fd03
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
  10:     0x653a8d3bc75e - std::panicking::rust_panic_with_hook::hafdc493a79370062
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:691:13
  11:     0x653a8d3bc659 - std::panicking::begin_panic_handler::{{closure}}::h0a64bc82e36bedc7
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:582:13
  12:     0x653a8d3bb316 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x653a8d3bc3b2 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  14:     0x653a8cde7903 - core::panicking::panic_fmt::h0f6ef0178afce4f2
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  15:     0x653a8d1480f8 - proc_macro2::Punct::new::hc4e4c65a0da28a44
  16:     0x653a8d00f829 - c2rust_ast_builder::builder::Builder::prepare_meta_list::h37e93a99ebcd3752
  17:     0x653a8d00fc6c - c2rust_ast_builder::builder::Builder::prepare_meta::h11e73cc8f052594d
  18:     0x653a8d015303 - c2rust_ast_builder::builder::Builder::meta_item_attr::h8dca6a584c13d456
  19:     0x653a8cf6620d - c2rust_transpile::translator::arrange_header::hcd280a098d0d7d33
  20:     0x653a8ce6da02 - c2rust_ast_printer::pprust::to_string::hbd6da562054b67ea
  21:     0x653a8cf646fe - c2rust_transpile::translator::translate::h253c06f6e7ad8b71
  22:     0x653a8ce1d64a - c2rust_transpile::transpile_single::h4e967c36ab87f735
  23:     0x653a8ce42d08 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::h248b2ea48306777c
  24:     0x653a8ce1a3e0 - c2rust_transpile::transpile::h54611f4657ac0056
  25:     0x653a8cded13c - c2rust_transpile::main::hbad40b339c5c5ec6
  26:     0x653a8cdf2313 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd39eac392534a019
  27:     0x653a8cdf2329 - std::rt::lang_start::{{closure}}::hac4ba16966a77c6a
  28:     0x653a8d3b292e - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb1327dc2ef3fecdf
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:287:13
  29:     0x653a8d3b292e - std::panicking::try::do_call::h4044173225fe83dd
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485:40
  30:     0x653a8d3b292e - std::panicking::try::hd8a722c09d156a53
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449:19
  31:     0x653a8d3b292e - std::panic::catch_unwind::hd2ca07971cf0119b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140:14
  32:     0x653a8d3b292e - std::rt::lang_start_internal::{{closure}}::h26d89d595cf47b70
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148:48
  33:     0x653a8d3b292e - std::panicking::try::do_call::hf47aa1aa005e5f1a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485:40
  34:     0x653a8d3b292e - std::panicking::try::h73d246b2423eaf4e
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449:19
  35:     0x653a8d3b292e - std::panic::catch_unwind::hbaaeae8f1b2f9915
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140:14
  36:     0x653a8d3b292e - std::rt::lang_start_internal::h76f3e81e6b8f13f9
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148:20
  37:     0x653a8cdf13c5 - main
  38:     0x7693cc42a1ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  39:     0x7693cc42a28b - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  40:     0x653a8cde8095 - _start
  41:                0x0 - <unknown>
krakotay@1 ~/D/c/e/build (master) [101]>
```
Same here

```
OS: Ubuntu 24.04.1 LTS on Windows 10 x86_64
Kernel: 5.15.153.1-microsoft-standard-WSL2

rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.81.0 (eeb90cda1 2024-09-04)`

C2Rust 0.19.0
LLVM 18.1.3
```

```
Transpiling CMakeCCompilerId.c
thread 'main' panicked at /home/ramones/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.87/src/lib.rs:847:13:
unsupported proc macro punctuation character '('
stack backtrace:
   0:     0x558ea7b1e485 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1b9dad2a88e955ff
   1:     0x558ea7b444bb - core::fmt::write::h4b5a1270214bc4a7
   2:     0x558ea7b1b75f - std::io::Write::write_fmt::hd04af345a50c312d
   3:     0x558ea7b1f5d1 - std::panicking::default_hook::{{closure}}::h96ab15e9936be7ed
   4:     0x558ea7b1f2ac - std::panicking::default_hook::h3cacb9c27561ad33
   5:     0x558ea7b1fc31 - std::panicking::rust_panic_with_hook::hfe205f6954b2c97b
   6:     0x558ea7b1fa97 - std::panicking::begin_panic_handler::{{closure}}::h6cb44b3a50f28c44
   7:     0x558ea7b1e949 - std::sys::backtrace::__rust_end_short_backtrace::hf1c1f2a92799bb0e
   8:     0x558ea7b1f724 - rust_begin_unwind
   9:     0x558ea7577723 - core::panicking::panic_fmt::h3d8fc78294164da7
  10:     0x558ea78b8a18 - proc_macro2::Punct::new::had17fe9889c4a206
  11:     0x558ea77962b6 - c2rust_ast_builder::builder::Builder::prepare_meta_list::haf191064db62c3d3
  12:     0x558ea77966dd - c2rust_ast_builder::builder::Builder::prepare_meta::h84520882eecab955
  13:     0x558ea779bcd6 - c2rust_ast_builder::builder::Builder::meta_item_attr::ha5370d676e391630
  14:     0x558ea765b7a3 - c2rust_transpile::translator::arrange_header::h876c41522a315399
  15:     0x558ea76d8e6e - c2rust_ast_printer::pprust::to_string::h7aa96472f65558f6
  16:     0x558ea7659b9f - c2rust_transpile::translator::translate::h3ed433b5c4c4c0d0
  17:     0x558ea75adfba - c2rust_transpile::transpile_single::h11ecbbbd19794b3f
  18:     0x558ea76c73e9 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::h63306556653a42b1
  19:     0x558ea75aaafc - c2rust_transpile::transpile::h07029eea5521b02f
  20:     0x558ea757ccc1 - c2rust_transpile::main::h8f5d0801c9b853ab
  21:     0x558ea758e703 - std::sys::backtrace::__rust_begin_short_backtrace::hbb752ebfbbefd5c6
  22:     0x558ea758e6f9 - std::rt::lang_start::{{closure}}::h85b29214297e2765
  23:     0x558ea7b164f0 - std::rt::lang_start_internal::h5e7c81cecd7f0954
  24:     0x558ea7587d25 - main
  25:     0x7fde5da831ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  26:     0x7fde5da8328b - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  27:     0x558ea7578045 - _start
  28:                0x0 - <unknown>
```
I met the same question
"unsupported proc macro punctuation character '('"

Here is my debugging process

1. use `gcc -E bits.c -o bits_preprocessed.c` to expand code without macros
2. `RUST_BACKTRACE=full c2rust transpile bits_preprocessed.c` to compile the expanded file

console outputs like

```
root@aae42b7e3ac8:/tractor/examples/gzip-1.2.4/c# RUST_BACKTRACE=full c2rust transpile bits_preprocessed.c
In file included from bits.c:55:
In file included from gzip.h:22:
/usr/include/stdio.h:195:48: error: '__malloc__' attribute takes no arguments
  195 |   __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) ;
      |                                                ^
/usr/include/stdio.h:229:90: error: '__malloc__' attribute takes no arguments
  229 |    __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (__builtin_free, 1)));
      |                                                                                          ^
/usr/include/stdio.h:266:48: error: '__malloc__' attribute takes no arguments
  266 |   __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) ;
      |                                                ^
/usr/include/stdio.h:300:48: error: '__malloc__' attribute takes no arguments
  300 |   __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) ;
      |                                                ^
/usr/include/stdio.h:309:48: error: '__malloc__' attribute takes no arguments
  309 |   __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) ;
      |                                                ^
/usr/include/stdio.h:315:89: error: '__malloc__' attribute takes no arguments
  315 |   __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) ;
      |                                                                                         ^
/usr/include/stdio.h:321:48: error: '__malloc__' attribute takes no arguments
  321 |   __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (fclose, 1))) ;
      |                                                ^
/usr/include/stdio.h:904:48: error: '__malloc__' attribute takes no arguments
  904 |   __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (pclose, 1))) ;
```
hi, guys, I got the same issue and I checked the error message and found that the proc-macro2-1.0.87 changed the lib.rs and add check for the macro character. It breaks the macro check.
Anybody could help to check the issue and fix it?
Thanks a lot.
I'm new to this project, but the method mentioned in [this issue](https://github.com/rust-embedded/svd2rust/issues/863) seems to work for me. 

I use the command below to install c2rust from crate.io and solve the problem:

```[shell]
cargo install c2rust --locked
```

Wish to help :)
Ha. 
I just add `--locked`, and 
```
 cargo install --git https://github.com/immunant/c2rust.git c2rust --locked
```
Works nice!
IMHO this should be reopened. `--locked` is not a real solution to this. 

The `proc_macro` crate [has added check for invalid punctuation](https://github.com/dtolnay/proc-macro2/pull/471), so `--locked` merely reverts to a version that allows invalid punctuation, instead of fixing whatever punctuation `c2rust` is trying to parse.

It seems like `prepare_meta_list` should construct a `Group` instead of creating `Punct`s with opening and closing parens.

Fix patch:
diff --git a/c2rust-ast-builder/src/builder.rs b/c2rust-ast-builder/src/builder.rs
index 252339c988..4fdba3c40b 100644
--- a/c2rust-ast-builder/src/builder.rs
+++ b/c2rust-ast-builder/src/builder.rs
@@ -537,13 +537,6 @@ impl Builder {
         let mut tokens = TokenStream::new();
         let comma_token = Token![,](self.span);
         let mut it = list.nested.into_iter();
-        tokens.extend(
-            Some(proc_macro2::TokenTree::Punct(proc_macro2::Punct::new(
-                '(',
-                proc_macro2::Spacing::Alone,
-            )))
-            .into_iter(),
-        );
         if let Some(value) = it.next() {
             value.to_tokens(&mut tokens);
         }
@@ -551,13 +544,12 @@ impl Builder {
             comma_token.to_tokens(&mut tokens);
             value.to_tokens(&mut tokens);
         }
-        tokens.extend(
-            Some(proc_macro2::TokenTree::Punct(proc_macro2::Punct::new(
-                ')',
-                proc_macro2::Spacing::Alone,
-            )))
-            .into_iter(),
-        );
+        let tokens = proc_macro2::TokenTree::Group(proc_macro2::Group::new(
+            proc_macro2::Delimiter::Parenthesis,
+            tokens,
+        ))
+        .into();
+
         PreparedMetaItem {
             path: list.path,
             tokens,


Test patch: