Closed
Description
If I try to compare an f64 with an &f64:
let bookcount = user.countmap.get("Book").unwrap();
assert!(bookcount < 91.0);
(where user.countmap is a HashMap<String, f64>) then rust tells me
error[E0308]: mismatched types
--> src/main.rs:134:29
|
134 | assert!(bookcount < 91.0);
| ^^^^ expected &f64, found floating-point variable
|
= note: expected type `&f64`
found type `{float}`
= help: try with `&91.0`
helpfully pointing me to the fact I need to add an & to the constant.
However if I do the same thing for equality comparison:
assert(bookcount == 91.0);
the error is much more obscure:
error[E0277]: the trait bound `&f64: std::cmp::PartialEq<{float}>` is not satisfied
--> src/main.rs:134:27
|
134 | assert!(bookcount == 91.0);
| ^^ can't compare `&f64` with `{float}`
|
= help: the trait `std::cmp::PartialEq<{float}>` is not implemented for `&f64`
It would be helpful if rust could produce E0308 for this mistake in all kinds of comparison.
I'm using this version of rust:
mnementh$ rustc --version --verbose
rustc 1.20.0 (f3d6973f4 2017-08-27)
binary: rustc
commit-hash: f3d6973f41a7d1fb83029c9c0ceaf0f5d4fd7208
commit-date: 2017-08-27
host: x86_64-unknown-linux-gnu
release: 1.20.0
LLVM version: 4.0