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 · 2 comments · May be fixed by #1063
Open

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

akonradi-signal opened this issue Aug 14, 2024 · 2 comments · May be fixed by #1063

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
@douglas-raillard-arm
Copy link

Is there a workaround for this ? I'm hitting the same problem, probably on some const_format::concatcp!() macro output.

@thomasgassmann
Copy link

I'm also hitting the same problem, downgrading to 0.26.0 fixed it for me.

bwoebi added a commit to DataDog/libdatadog that referenced this issue Mar 20, 2025

Verified

This commit was signed with the committer’s verified signature.
bwoebi Bob Weinand
Works around mozilla/cbindgen#993 in cbindgen 0.27+

Signed-off-by: Bob Weinand <[email protected]>
bwoebi added a commit to DataDog/libdatadog that referenced this issue Mar 20, 2025

Verified

This commit was signed with the committer’s verified signature.
bwoebi Bob Weinand
Works around mozilla/cbindgen#993 in cbindgen 0.27+

Signed-off-by: Bob Weinand <[email protected]>
bwoebi added a commit to DataDog/libdatadog that referenced this issue Mar 20, 2025

Verified

This commit was signed with the committer’s verified signature.
bwoebi Bob Weinand
Works around mozilla/cbindgen#993 in cbindgen 0.27+

Signed-off-by: Bob Weinand <[email protected]>
bwoebi added a commit to DataDog/libdatadog that referenced this issue Mar 20, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Works around mozilla/cbindgen#993 in cbindgen 0.27+

Signed-off-by: Bob Weinand <[email protected]>
ogoffart added a commit to slint-ui/cbindgen that referenced this issue Mar 31, 2025
@ogoffart ogoffart linked a pull request Mar 31, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants