Skip to content

Regression: Matching on function pointers fails when one of the formal params implements custom PartialEq #63479

Closed
@archseer

Description

@archseer

A contrived playground example:

#[derive(Eq)]
struct A {
  a: i64   
}

impl PartialEq for A {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.a.eq(&other.a)
    }
}

type Fn = fn(&[A]);

fn my_fn(args: &[A]) {
  println!("hello world");
}

const TEST: Fn = my_fn;

struct B(Fn);

fn main() {
  let s = B(my_fn);
  match s {
    B(TEST) => println!("matched"),
    _ => println!("didn't match")
  };
}

This code will build on stable and beta, but not on nightly.

error: to use a constant of type `A` in a pattern, `A` must be annotated with `#[derive(PartialEq, Eq)]`

It looks like it's related to #62307 possibly?

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions