Repository: rust-analyzer/rust-analyzer (rust)

Issue:
Hovering over variable usage fails to infer type
In the following:
```rust
fn quux(x: i32) {
    let y = 92;
    1 + y<|>;
}
```

Hovering over the `let` binding of `y` gives an `i32` but hovering over `y` at the cursor position fails to find the type

Pull request description:
Fix type inference of binops on int/float variables
Fixes #651.

Patch:
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 5193900e01..028c1882f7 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -190,12 +190,7 @@ where
             self.populate_module(module_id, Arc::clone(items));
         }
 
-        let mut iter = 0;
         loop {
-            iter += 1;
-            if iter > 1000 {
-                panic!("failed to reach fixedpoint after 1000 iters")
-            }
             let processed_imports_count = self.processed_imports.len();
             for &module_id in self.input.keys() {
                 self.db.check_canceled();
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 714eaaae53..179ebddeec 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -790,7 +790,10 @@ fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
         | BinaryOp::BitwiseAnd
         | BinaryOp::BitwiseOr
         | BinaryOp::BitwiseXor => match rhs_ty {
-            Ty::Int(..) | Ty::Float(..) => rhs_ty,
+            Ty::Int(..)
+            | Ty::Float(..)
+            | Ty::Infer(InferTy::IntVar(..))
+            | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty,
             _ => Ty::Unknown,
         },
         BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown,


Test patch:
diff --git a/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap b/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap
new file mode 100644
index 0000000000..d23d3f1392
--- /dev/null
+++ b/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap
@@ -0,0 +1,13 @@
+---
+created: "2019-01-25T20:31:47.275112244+00:00"
+creator: insta@0.5.2
+expression: "&result"
+source: crates/ra_hir/src/ty/tests.rs
+---
+[11; 41) '{     ...+ y; }': ()
+[21; 22) 'y': i32
+[25; 27) '92': i32
+[33; 34) '1': i32
+[33; 38) '1 + y': i32
+[37; 38) 'y': i32
+
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 92c74cf008..389bdaf237 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -532,6 +532,19 @@ fn test() {
     );
 }
 
+#[test]
+fn bug_651() {
+    check_inference(
+        "bug_651",
+        r#"
+fn quux() {
+    let y = 92;
+    1 + y;
+}
+"#,
+    );
+}
+
 fn infer(content: &str) -> String {
     let (db, _, file_id) = MockDatabase::with_single_file(content);
     let source_file = db.source_file(file_id);