Closed
Description
I've faced with compiler error on arithmetic operations with borrowed values. After some simplification of my code, it was reduced to following program:
fn main() {
let a: i32 = 0;
let b: i32 = 0;
let aa = &a;
// works
if b - aa < 0 { }
// unexpected e0308 error
if b < aa { }
}
Here we have two if
statements. First compiles OK, and second fails with compiler error E0308: It complains on "incompatible" types i32
and &i32
. However, expression in first if
also contains variables of different types, and does not irritate Rust compiler.
I suppose it's a bug, because this behaviour is counter-intuitive.
Note: I've tested it on stable 1.2.0 and nightly versions (via http://play.rust-lang.org) - results are the same.