Skip to content

address: current PartialEq implementation breaks match-against-const situations #345

@rustopian

Description

@rustopian

Problem

The new PartialEq implementation on Address will break match-against-const contexts (incl. in agave here), as StructuralPartialEq can no longer be auto-derived.

This also breaks other similar patterns such as if let against constant.

Rust doesn't allow constants to be used as patterns for matching when PartialEq is hand-implemented - since that could, for example, expose private implementation details.

Solutions

There are a few options here, including these briefly-considered possibilities:

  • require dependents to avoid match patterns against constants (and document this), which makes some semantic sense for Address
  • restore derive(PartialEq) and move the custom equality logic back behind a separate method/trait, as before
  • require dependents wishing to match against constants to use a new simple helper that exposes a #[derive(PartialEq)] type
  • assorted solutions that split the type, such as raw and wrapper
  • impl StructuralPartialEq, but who knows when that will be stable

For now, I'm adapting agave code when needed, e.g. switching match to if/else or guarded match patterns.

cc @febo @grod220

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions