2592: Add std::ops::Index support for infering r=edwin0cheng a=edwin0cheng

see also #2534

Seem like this can't fix #2534 for this case:

```rust
fn foo3(bar: [usize; 2]) {
    let baz = bar[1];   // <--- baz is still unknown ?
    println!("{}", baz);
}
```

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
bors[bot] 2019-12-20 14:36:53 +00:00 committed by GitHub
commit d590f6ce12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 5 deletions

View file

@ -422,10 +422,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
}
}
Expr::Index { base, index } => {
let _base_ty = self.infer_expr_inner(*base, &Expectation::none());
let _index_ty = self.infer_expr(*index, &Expectation::none());
// FIXME: use `std::ops::Index::Output` to figure out the real return type
Ty::Unknown
let base_ty = self.infer_expr_inner(*base, &Expectation::none());
let index_ty = self.infer_expr(*index, &Expectation::none());
self.resolve_associated_type_with_params(
base_ty,
self.resolve_ops_index_output(),
&[index_ty],
)
}
Expr::Tuple { exprs } => {
let mut tys = match &expected.ty {