Repository: intellij-rust/intellij-rust
Issue: vec dereference error

<!--
Hello and thank you for the issue!
If you would like to report a bug, we have added some points below that you can fill out.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **Intellij-Rust plugin version:**
Latest one I think
* **Rust toolchain version:**
nightly 
* **IDE name and version:**
intellJ IDEA
* **Operating system:**
macOS
## Problem description
  
[Screen Shot 2018-10-08 at 2.45.25 PM.PDF](https://github.com/intellij-rust/intellij-rust/files/2458145/Screen.Shot.2018-10-08.at.2.45.25.PM.PDF)


## Steps to reproduce
just rewrite the code above
<!--
Please include as much of your codebase as needed to reproduce the error.
If the relevant files are large, please provide a link to a public repository or a [Gist](https://gist.github.com/).
-->


Changed files:
src/test/kotlin/org/rust/ide/inspections/RsAssignToImmutableInspectionTest.kt, src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt

diff --git a/src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt b/src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt
index 410028f19..e97c6bb5f 100644
--- a/src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt
+++ b/src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt
@@ -1419,24 +1419,29 @@ class RsFnInferenceContext(
         fun isArrayToSlice(prevType: Ty?, type: Ty?): Boolean =
             prevType is TyArray && type is TySlice
 
-        val containerType = expr.containerExpr?.inferType() ?: return TyUnknown
-        val indexType = ctx.resolveTypeVarsIfPossible(expr.indexExpr?.inferType() ?: return TyUnknown)
+        val containerExpr = expr.containerExpr ?: return TyUnknown
+        val indexExpr = expr.indexExpr ?: return TyUnknown
+
+        val containerType = containerExpr.inferType()
+        val indexType = ctx.resolveTypeVarsIfPossible(indexExpr.inferType())
 
         var derefCount = -1 // starts with -1 because the fist element of the coercion sequence is the type itself
         var prevType: Ty? = null
+        var result: Ty = TyUnknown
         for (type in lookup.coercionSequence(containerType)) {
             if (!isArrayToSlice(prevType, type)) derefCount++
 
             val outputType = lookup.findIndexOutputType(type, indexType)
             if (outputType != null) {
-                expr.containerExpr?.let { ctx.addAdjustment(it, Adjustment.Deref(containerType), derefCount) }
-                return outputType.register()
+                result = outputType.register()
+                break
             }
 
             prevType = type
         }
 
-        return TyUnknown
+        ctx.addAdjustment(containerExpr, Adjustment.Deref(containerType), derefCount)
+        return result
     }
 
     private fun inferMacroExprType(expr: RsMacroExpr): Ty {
diff --git a/src/test/kotlin/org/rust/ide/inspections/RsAssignToImmutableInspectionTest.kt b/src/test/kotlin/org/rust/ide/inspections/RsAssignToImmutableInspectionTest.kt
index c1ef879ce..b9cac9902 100644
--- a/src/test/kotlin/org/rust/ide/inspections/RsAssignToImmutableInspectionTest.kt
+++ b/src/test/kotlin/org/rust/ide/inspections/RsAssignToImmutableInspectionTest.kt
@@ -82,4 +82,11 @@ class RsAssignToImmutableInspectionTest : RsInspectionsTestBase(RsAssignToImmuta
             <error descr="Cannot assign to immutable dereference of raw pointer [E0594]">*p = 1</error>;
         }
     """)
+
+    fun `test assign to index expr of unknown type`() = checkByText("""
+        fn main() {
+            let xs = &mut unknownType;
+            xs[0] = 1;
+        }
+    """)
 }