Skip to content

Breaking change between 1.5.0 and 1.5.1: U256 cannot be used in a match pattern #50

Description

@gregorydemay

Starting 1.5.1 U256 can no longer be used in a match pattern.

The following example pass with 1.5.0 and Rust 1.87.0

#[test]
fn should_be_less_than_two() {
    let value = ethnum::u256::new(1);
    let less_than_two = match value {
        ethnum::u256::ZERO => true,
        ethnum::u256::ONE => true,
        _ => false,
    };
    assert!(less_than_two);
}

However, the same test will no longer compile once updating ethnum to 1.5.1. The compilation error is as follows:

error: constant of non-structural type `U256` in a pattern
  --> src/tests.rs:5:9
   |
5  |         ethnum::u256::ZERO => true,
   |         ^^^^^^^^^^^^^^^^^^ constant of non-structural type
   |
  ::: /Users/greg/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ethnum-1.5.1/src/uint.rs:18:1
   |
18 | pub struct U256(pub [u128; 2]);
   | --------------- `U256` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
...
22 |     pub const ZERO: Self = U256([0; 2]);
   |     -------------------- constant defined here
   |
   = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details

Looking at the changelog, I suspect this might be related to #38.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions