Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when parsing a generic type with empty tuple as default type parameter #993

Open
akonradi-signal opened this issue Aug 14, 2024 · 0 comments

Comments

@akonradi-signal
Copy link
Contributor

#959 added support for default generic type parameters. This broke some existing use cases, in particular where a type is defined with a type parameter with a default, but where all usages specify the type parameter.

MRE:

#[repr(C)]
pub struct NeverUsedWithDefault<T = ()> {
  field: T
}

#[no_mangle]
pub extern "c" fn with_i32(x: NeverUsedWithDefault<i32>) {}

Running cbindgen against that produces the following:

thread 'main' panicked at src/bindgen/parser.rs:928:82:
called `Result::unwrap()` on an `Err` value: "unsupported generic type default: Some(Type::Tuple { paren_token: Paren, elems: [] })"
stack backtrace:
   0: rust_begin_unwind
             at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/std/src/panicking.rs:661:5
   1: core::panicking::panic_fmt
             at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/core/src/panicking.rs:74:14
   2: core::result::unwrap_failed
             at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/core/src/result.rs:1679:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/core/src/result.rs:1102:23
   4: cbindgen::bindgen::parser::Parse::load_syn_struct
             at ./src/bindgen/parser.rs:928:21
   5: cbindgen::bindgen::parser::Parse::load_syn_crate_mod
             at ./src/bindgen/parser.rs:524:21
   6: cbindgen::bindgen::parser::Parser::process_mod
             at ./src/bindgen/parser.rs:306:30
   7: cbindgen::bindgen::parser::Parser::parse_mod
             at ./src/bindgen/parser.rs:277:9
   8: cbindgen::bindgen::parser::parse_src
             at ./src/bindgen/parser.rs:59:5
   9: cbindgen::bindgen::builder::Builder::generate
             at ./src/bindgen/builder.rs:375:33
  10: cbindgen::load_bindings
             at ./src/main.rs:98:16
  11: cbindgen::main
             at ./src/main.rs:327:26
  12: core::ops::function::FnOnce::call_once
             at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/core/src/ops/function.rs:250:5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant