Hpmason / retour-rs

A cross-platform detour library written in Rust
Other
99 stars 18 forks source link

Add support for trailing commas in `static_detour` function signatures. #44

Closed avalsch closed 7 months ago

avalsch commented 7 months ago

When detouring functions with long signatures, it's convenient to layout function parameters on their own lines. When doing this, adding a trailing comma matches the format rustfmt uses for long function signatures. This currently causes a recursion error.

Allowing a trailing comma would add flexibility, and remove an error message which is unclear.

Example

use std::{ffi::c_void, ptr::NonNull};

retour::static_detour! {
    static Foo: unsafe extern "C" fn(
        Option<NonNull<c_void>>,
        Option<NonNull<c_void>>,
        Option<NonNull<c_void>>,
        Option<NonNull<c_void>>,
    );
}
error: recursion limit reached while expanding $crate::static_detour! --> src/lib.rs:3:1 3 / retour::static_detour! { 4 pub static Foo: unsafe extern "C" fn( 5 Option<NonNull>, 6 Option<NonNull>, ... 9 ); 10 } _^

= help: consider increasing the recursion limit by adding a #![recursion_limit = "256"] attribute to your crate (testing) = note: this error originates in the macro $crate::static_detour which comes from the expansion of the macro retour::static_detour (in Nightly builds, run with -Z macro-backtrace for more info)