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

Compile error messages need to improve when assert_eq!(None, None) #19295

Closed
liigo opened this issue Nov 25, 2014 · 2 comments
Closed

Compile error messages need to improve when assert_eq!(None, None) #19295

liigo opened this issue Nov 25, 2014 · 2 comments

Comments

@liigo
Copy link
Contributor

liigo commented Nov 25, 2014

struct A {
    v: int,
}

fn find_a() -> Option<A> {
    None
}

fn main() {
    let a = find_a();
    assert!(a.is_none());
    assert_eq!(a, None); // Got too many irrelevant compile errors!
}

Compile errors:

<std macros>:6:23: 6:50 error: binary operation `==` cannot be applied to type `core::option::Option<A>`
<std macros>:6                 if !((*given_val == *expected_val) &&
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:1:1: 14:2 note: in expansion of assert_eq!
assert_eq_none.rs:12:2: 12:22 note: expansion site
<std macros>:9:56: 9:66 error: the trait `core::fmt::Show` is not implemented for the type `A`
<std macros>:9                            (left: `{}`, right: `{}`)", *given_val, *expected_val)
                                                                      ^~~~~~~~~~
note: in expansion of format_args!
<std macros>:32:9: 33:6 note: expansion site
<std macros>:1:1: 34:2 note: in expansion of panic!
<std macros>:8:21: 10:18 note: expansion site
<std macros>:1:1: 14:2 note: in expansion of assert_eq!
assert_eq_none.rs:12:2: 12:22 note: expansion site
<std macros>:9:56: 9:66 note: the trait `core::fmt::Show` must be implemented because it is required by `core::fmt::Show::fmt`
<std macros>:9                            (left: `{}`, right: `{}`)", *given_val, *expected_val)
                                                                      ^~~~~~~~~~
note: in expansion of format_args!
<std macros>:32:9: 33:6 note: expansion site
<std macros>:1:1: 34:2 note: in expansion of panic!
<std macros>:8:21: 10:18 note: expansion site
<std macros>:1:1: 14:2 note: in expansion of assert_eq!
assert_eq_none.rs:12:2: 12:22 note: expansion site
<std macros>:9:68: 9:81 error: the trait `core::fmt::Show` is not implemented for the type `A`
<std macros>:9                            (left: `{}`, right: `{}`)", *given_val, *expected_val)
                                                                                  ^~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:32:9: 33:6 note: expansion site
<std macros>:1:1: 34:2 note: in expansion of panic!
<std macros>:8:21: 10:18 note: expansion site
<std macros>:1:1: 14:2 note: in expansion of assert_eq!
assert_eq_none.rs:12:2: 12:22 note: expansion site
<std macros>:9:68: 9:81 note: the trait `core::fmt::Show` must be implemented because it is required by `core::fmt::Show::fmt`
<std macros>:9                            (left: `{}`, right: `{}`)", *given_val, *expected_val)
                                                                                  ^~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:32:9: 33:6 note: expansion site
<std macros>:1:1: 34:2 note: in expansion of panic!
<std macros>:8:21: 10:18 note: expansion site
<std macros>:1:1: 14:2 note: in expansion of assert_eq!
assert_eq_none.rs:12:2: 12:22 note: expansion site
<std macros>:7:23: 7:50 error: the trait `core::cmp::PartialEq` is not implemented for the type `A`
<std macros>:7                      (*expected_val == *given_val)) {
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:1:1: 14:2 note: in expansion of assert_eq!
assert_eq_none.rs:12:2: 12:22 note: expansion site
error: aborting due to 4 previous errors

Adding #[deriving(PartialEq,Eq,Show)] to struct A should resolve these compile errors.

@lifthrasiir
Copy link
Contributor

This really is #1679. The type system needs an information about the set of active variants.

@steveklabnik
Copy link
Member

Yes, agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants