Skip to content
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

Compiler should be able to compile EnumVariant(foo) == function_returning_enum() without PartialEq #57782

Open
In-line opened this issue Jan 20, 2019 · 3 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@In-line
Copy link
Contributor

In-line commented Jan 20, 2019

Given this pseudocode

let result: bool = Ok(something) == some_function_returning_result();

It should be transformed to this pseudocode

let result: bool = match some_function_returning_result() {
    Ok(something) => true,
    _ => false,
};

Currently I get this error.

error[E0277]: can't compare `errors::Error` with `errors::Error`
   --> src/rustup/toolchain.rs:349:35
    |
349 |                     Ok(something) == some_function_returning_result()
    |                                   ^^ no implementation for `errors::Error == errors::Error`
    |
    = help: the trait `std::cmp::PartialEq` is not implemented for `errors::Error`
    = note: required because of the requirements on the impl of `std::cmp::PartialEq` for `std::result::Result<std::string::String, errors::Error>`

It would be nice syntax sugar to have not only for Result, but for any generic enum.

@petrochenkov
Copy link
Contributor

cc rust-lang/rfcs#929 (comment)

@estebank estebank added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Jan 20, 2019
@scottmcm
Copy link
Member

scottmcm commented Jan 21, 2019

I think this is an RFC issue -- for example it could be made to work with enum variants being types, and PartialEq being defined on those against their enum parent type, or with something like the is expressions that petrochenkov linked, or the matches! macro. I suspect it's not something that would ever be done as written, though, since there's nothing that says equality needs to work the way this transformation would be assuming: different variants are allowed to be considered equal.

@Centril Centril added needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Jan 22, 2019
@In-line
Copy link
Contributor Author

In-line commented Jan 24, 2019

Thanks. I will think more carefully about this issue and try to write RFC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants