uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Non-exhaustive enums seem to trouble uniffi

Open tmathern opened this issue 9 months ago • 5 comments

Repro from branch in https://github.com/contentauth/c2pa-python/pull/82 (clone, checkout the branch, run `cargo build).

In our code,

  • impl Signer for RemoteSigner has a function, alg, that returns a SigningAlg enum.
  • The enum is defined in a dependency, c2pa-rs. In there, SigningAlg is a non exhaustive enum: https://github.com/contentauth/c2pa-rs/blob/main/internal/crypto/src/raw_signature/signing_alg.rs#L31

It seems this troubles uniffi, as the build fails:

   Compiling c2pa-python v0.6.2 (/git/@CAI/c2pa-python)
error[E0004]: non-exhaustive patterns: `_` not covered
   --> /git/@CAI/c2pa-python/target/debug/build/c2pa-python-3be618cc7bdb8e16/out/c2pa.uniffi.rs:115:1
    |
115 | #[::uniffi::udl_derive(Enum)]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
    |
note: `SigningAlg` defined here
   --> /.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2pa-crypto-0.3.0/src/raw_signature/signing_alg.rs:32:1
    |
32  | pub enum SigningAlg {
    | ^^^^^^^^^^^^^^^^^^^
    = note: the matched value is of type `SigningAlg`
    = note: `SigningAlg` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
    = note: this error originates in the attribute macro `::uniffi::udl_derive` (in Nightly builds, run with -Z macro-backtrace for more info)
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
    |
115 | #[::uniffi::udl_derive(Enum)], _ => todo!()
    |                              ++++++++++++++

For more information about this error, try `rustc --explain E0004`.

tmathern avatar Jan 22 '25 00:01 tmathern