diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-20 14:36:53 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-20 14:36:53 +0000 |
commit | d590f6ce12bf4d0311138846e26951b613f0afd4 (patch) | |
tree | d73816f61ccdaa2b9710ff5c7efbb3b62367c9c3 /crates/ra_hir_ty/src/infer.rs | |
parent | 81a1b14d78d6078c63dd42c09da5a3e171c85a3a (diff) | |
parent | 76d688a328ab53b6264f9e489b88524377a7271d (diff) |
Merge #2592
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 <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/infer.rs')
-rw-r--r-- | crates/ra_hir_ty/src/infer.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 98ba05fc2..bbbc391c4 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -363,14 +363,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
363 | } | 363 | } |
364 | 364 | ||
365 | fn resolve_associated_type(&mut self, inner_ty: Ty, assoc_ty: Option<TypeAliasId>) -> Ty { | 365 | fn resolve_associated_type(&mut self, inner_ty: Ty, assoc_ty: Option<TypeAliasId>) -> Ty { |
366 | self.resolve_associated_type_with_params(inner_ty, assoc_ty, &[]) | ||
367 | } | ||
368 | |||
369 | fn resolve_associated_type_with_params( | ||
370 | &mut self, | ||
371 | inner_ty: Ty, | ||
372 | assoc_ty: Option<TypeAliasId>, | ||
373 | params: &[Ty], | ||
374 | ) -> Ty { | ||
366 | match assoc_ty { | 375 | match assoc_ty { |
367 | Some(res_assoc_ty) => { | 376 | Some(res_assoc_ty) => { |
368 | let ty = self.table.new_type_var(); | 377 | let ty = self.table.new_type_var(); |
378 | let builder = Substs::build_for_def(self.db, res_assoc_ty) | ||
379 | .push(inner_ty) | ||
380 | .fill(params.iter().cloned()); | ||
369 | let projection = ProjectionPredicate { | 381 | let projection = ProjectionPredicate { |
370 | ty: ty.clone(), | 382 | ty: ty.clone(), |
371 | projection_ty: ProjectionTy { | 383 | projection_ty: ProjectionTy { |
372 | associated_ty: res_assoc_ty, | 384 | associated_ty: res_assoc_ty, |
373 | parameters: Substs::single(inner_ty), | 385 | parameters: builder.build(), |
374 | }, | 386 | }, |
375 | }; | 387 | }; |
376 | self.obligations.push(Obligation::Projection(projection)); | 388 | self.obligations.push(Obligation::Projection(projection)); |
@@ -517,6 +529,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
517 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 529 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
518 | Some(struct_.into()) | 530 | Some(struct_.into()) |
519 | } | 531 | } |
532 | |||
533 | fn resolve_ops_index_output(&self) -> Option<TypeAliasId> { | ||
534 | let path = path![std::ops::Index]; | ||
535 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | ||
536 | self.db.trait_data(trait_).associated_type_by_name(&name![Output]) | ||
537 | } | ||
520 | } | 538 | } |
521 | 539 | ||
522 | /// The kinds of placeholders we need during type inference. There's separate | 540 | /// The kinds of placeholders we need during type inference. There's separate |