Skip to content

Error "binary operation == cannot be applied to type" -> print note that PartialEq might be missing #28837

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

Closed
AndiDog opened this issue Oct 4, 2015 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@AndiDog
Copy link
Contributor

AndiDog commented Oct 4, 2015

The error

<std macros>:5:8: 5:18 error: binary operation `==` cannot be applied to type `core::result::Result<collections::string::String, MyError>` [E0369]
<std macros>:5 if ! ( * left_val == * right_val ) {
                      ^~~~~~~~~~
src\lib.rs:34:3: 34:41 note: in this expansion of assert_eq! (defined in <std macros>)

should give a note that the PartialEq trait might be missing. In the example below, I couldn't spot for a very long time why the Result<T, StringLikeType> was working but my own error type failed with the error above. Rust beginners like me would enjoy such hints and save time finding simple problems.

use std::borrow::Cow;
use std::result;

pub type StrCow = Cow<'static, str>;
#[derive(Debug)] // missing PartialEq!!!
pub enum MyError { }

pub type MyResultStrError<T> = result::Result<T, &'static str>;
pub type MyResultMyError<T> = result::Result<T, MyError>;

pub fn str_error() -> MyResultStrError<String>
{
    Ok("abc".into())
}

pub fn my_error() -> MyResultMyError<String>
{
    Ok("def".into())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_str_error() {
        assert_eq!(str_error(), Ok("abc".to_owned()));
    }

    #[test]
    fn test_my_error() {
        let res = my_error();
        assert!(res.is_ok());
        assert_eq!(res, Ok("abc".to_owned())); // <-- build error here
    }
}

Relevant code:

span_err!(fcx.tcx().sess, lhs_expr.span, E0369,

rustc --version --verbose: rustc 1.5.0-nightly (98df458 2015-10-03)

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 4, 2015
bors added a commit that referenced this issue Oct 17, 2015
this PR adds notes for missing `PartialEq` and `PartialOrd`. I've added a test case but it seems like `NOTE` is ignored by the test runner.

#28837
@bors bors closed this as completed in 6c209d1 Oct 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

2 participants