You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
structural_match bug: deep refs like & &B leak use of PartialEq #62307
rust-lang/rfcs#1445 says that we're supposed to reject uses of consts with ADT's that don't implement #[structural_match] (i.e. ADT's that do not do #[derive(PartialEq, Eq)].
Unfortunately, we did not quite finish the job. Consider the following code (play):
#[derive(Debug)]structB(i32);// Overriding PartialEq to use this strange notion of equality exposes// whether `match` is using structural-equality or method-dispatch// under the hood, which is the antithesis of rust-lang/rfcs#1445implPartialEqforB{fneq(&self,other:&B) -> bool{ std::cmp::min(self.0, other.0) == 0}}constZER_B:&&B = &&B(0);constONE_B:&&B = &&B(1);fnmain(){ifletONE_B = ZER_B{println!("CLAIM Z: {:?} matches {:?}",ONE_B,ZER_B);}ifletONE_B = ONE_B{println!("CLAIM O: {:?} matches {:?}",ONE_B,ONE_B);}}
This prints:
CLAIM Z: B(1) matches B(0)
but I would expect to see something like the error you get if you use constants of type &B instead of & &B:
error: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
--> src/main.rs:15:12
|
15 | if let ONE_B = ZER_B {
| ^^^^^
Activity
Centril commentedon Jul 2, 2019
Me and @pnkfelix briefly discussed this on Discord.
pnkfelix commentedon Jul 3, 2019
I have a patch for this in progress.
pnkfelix commentedon Jul 3, 2019
(the change suggested in PR #62339 fixes this and has a regression test for it.)
Auto merge of #62339 - pnkfelix:issue-61188-use-visitor-for-structura…