0

I want to use int in a generic class which require its generic type to implement the core::cmp::PartialEq trait. I know int is implementing it because I can do 4 != 5. The problem is that the compiler doesn't recognise and fire the following error :

error: unable to infer enough type information to locate the impl of the trait core::cmp::PartialEq for the type <generic integer #2>; type annotations required src/binary_tree.rs:80 let tree = Node::new_node(box 10);

src/binary_tree.rs:80:13: 80:27 note: the trait core::cmp::PartialEq must be implemented because it is required by Node<T>::new_node

Can you help me to find the implementation of partialeq for int ?

1 Answer 1

8

10 is not an int literal. It is a generic integer literal—it may be int, i8, i16, i32, i64, uint, u8, u16, u32 or u64. Which it will be is inferred.

In this case you have not given it anything to infer it with, and so it is unable to determine what type your number is, hence “type annotations required”. If you want it to be an int, write 10i.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.