-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The PartialEq implementation for tuples isn't general enough #105092
Labels
C-bug
Category: This is a bug.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Comments
rustbot
added
the
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
label
Dec 10, 2023
copybara-service bot
pushed a commit
to google/googletest-rust
that referenced
this issue
Nov 11, 2024
…nt-wise. This adds special cases in `verify_eq!` so that, when doing `eq` matching on sequences of tuples-like elements, the matcher applies tuple matching, distributing `eq` pointwise. This improves the ergonomics of tests that check for tuple contents, such as: ```rust let hash_map: std::collections::HashMap<String, String> = std::collections::HashMap::from([ ("a".into(), "A".into()), ("b".into(), "B".into())]); verify_eq!(hash_map, {("a", "A"), ("b", "B")}) ``` because the matcher for `&str` is compatible with `&String`. The specialization applies on the inner structure; without it, the general matcher on tuples doesn't apply in the above case due to the definition of `PartialEq` on whole tuples, which is currently limited by rust-lang/rust#105092. PiperOrigin-RevId: 693858563
copybara-service bot
pushed a commit
to google/googletest-rust
that referenced
this issue
Nov 11, 2024
…nt-wise. This adds special cases in `verify_eq!` so that, when doing `eq` matching on sequences of tuples-like elements, the matcher applies tuple matching, distributing `eq` pointwise. This improves the ergonomics of tests that check for tuple contents, such as: ```rust let hash_map: std::collections::HashMap<String, String> = std::collections::HashMap::from([ ("a".into(), "A".into()), ("b".into(), "B".into())]); verify_eq!(hash_map, {("a", "A"), ("b", "B")}) ``` because the matcher for `&str` is compatible with `&String`. The specialization applies on the inner structure; without it, the general matcher on tuples doesn't apply in the above case due to the definition of `PartialEq` on whole tuples, which is currently limited by rust-lang/rust#105092. PiperOrigin-RevId: 693858563
copybara-service bot
pushed a commit
to google/googletest-rust
that referenced
this issue
Nov 12, 2024
This adds special cases in `verify_eq!` so that, when doing `eq` matching on sequences of tuple elements, the matcher applies tuple matching, distributing `eq` pointwise. This improves the ergonomics of tests that check for tuple contents, such as: ```rust let hash_map: std::collections::HashMap<String, String> = std::collections::HashMap::from([ ("a".into(), "A".into()), ("b".into(), "B".into())]); verify_eq!(hash_map, {("a", "A"), ("b", "B")}) ``` because the matcher for `&str` is compatible with `&String`. The specialization applies on the inner structure; without it, the general matcher on tuples doesn't apply in the above case due to the definition of `PartialEq` on whole tuples, which is currently limited by rust-lang/rust#105092. PiperOrigin-RevId: 693858563
copybara-service bot
pushed a commit
to google/googletest-rust
that referenced
this issue
Nov 12, 2024
This adds special cases in `verify_eq!` so that, when doing `eq` matching on sequences of tuple elements, the matcher applies tuple matching, distributing `eq` pointwise. This improves the ergonomics of tests that check for tuple contents, such as: ```rust let hash_map: std::collections::HashMap<String, String> = std::collections::HashMap::from([ ("a".into(), "A".into()), ("b".into(), "B".into())]); verify_eq!(hash_map, {("a", "A"), ("b", "B")}) ``` because the matcher for `&str` is compatible with `&String`. The specialization applies on the inner structure; without it, the general matcher on tuples doesn't apply in the above case due to the definition of `PartialEq` on whole tuples, which is currently limited by rust-lang/rust#105092. PiperOrigin-RevId: 693858563
copybara-service bot
pushed a commit
to google/googletest-rust
that referenced
this issue
Nov 12, 2024
This adds special cases in `verify_eq!` so that, when doing `eq` matching on sequences of tuple elements, the matcher applies tuple matching, distributing `eq` pointwise. This improves the ergonomics of tests that check for tuple contents, such as: ```rust let hash_map: std::collections::HashMap<String, String> = std::collections::HashMap::from([ ("a".into(), "A".into()), ("b".into(), "B".into())]); verify_eq!(hash_map, {("a", "A"), ("b", "B")}) ``` because the matcher for `&str` is compatible with `&String`. The specialization applies on the inner structure; without it, the general matcher on tuples doesn't apply in the above case due to the definition of `PartialEq` on whole tuples, which is currently limited by rust-lang/rust#105092. PiperOrigin-RevId: 695528259
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-bug
Category: This is a bug.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
A coworker recently ran into a situation where tuples aren't comparable even when their individual elements are. I was able to boil it down to the following code snippet:
(playground)
I expected the above snippet to compile and run successfully, but the code fails to compile.
I always thought the standard library would have something like this:
But it seems like it only implements
PartialEq
when the left-hand side tuple and right-hand side tuple have the exact same type.Meta
This is reproducible on the Rust playground using stable (1.65.0).
The text was updated successfully, but these errors were encountered: