Skip to content

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

@AndiDog

Description

@AndiDog

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions