Skip to content

Unexpected compiler error E0308 on arithmetic with borrowed values #28293

Closed
@vdmit

Description

@vdmit

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions