diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-09 08:50:18 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-09 08:50:18 +0100 |
commit | f59cd1a4a0d6c369025a7014e838d25f91d478e4 (patch) | |
tree | 2c4b9dc868a87507ed63e9dc46530cc60f38ae64 /crates/ra_hir/src/ty/lower.rs | |
parent | 35f28c538a9b9f461bb4db1a78d02e9f02a3d296 (diff) | |
parent | 9afbf2dff43dee3227358f10162d4c77d192ce7a (diff) |
Merge #1515
1515: Trait environment r=matklad a=flodiebold
This adds the environment, i.e. the set of `where` clauses in scope, when solving trait goals. That means that e.g. in
```rust
fn foo<T: SomeTrait>(t: T) {}
```
, we are able to complete methods of `SomeTrait` on the `t`. This affects the trait APIs quite a bit (since every method that needs to be able to solve for some trait needs to get this environment somehow), so I thought I'd do it rather sooner than later ;)
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/lower.rs')
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index b48ada760..ca47d6e96 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -317,6 +317,18 @@ pub(crate) fn type_for_field(db: &impl HirDatabase, field: StructField) -> Ty { | |||
317 | Ty::from_hir(db, &resolver, type_ref) | 317 | Ty::from_hir(db, &resolver, type_ref) |
318 | } | 318 | } |
319 | 319 | ||
320 | pub(crate) fn trait_env(db: &impl HirDatabase, resolver: &Resolver) -> Arc<super::Environment> { | ||
321 | let predicates = resolver | ||
322 | .where_predicates_in_scope() | ||
323 | .map(|pred| { | ||
324 | TraitRef::for_where_predicate(db, &resolver, pred) | ||
325 | .map_or(GenericPredicate::Error, GenericPredicate::Implemented) | ||
326 | }) | ||
327 | .collect::<Vec<_>>(); | ||
328 | |||
329 | Arc::new(super::Environment { predicates }) | ||
330 | } | ||
331 | |||
320 | /// Resolve the where clause(s) of an item with generics. | 332 | /// Resolve the where clause(s) of an item with generics. |
321 | pub(crate) fn generic_predicates_query( | 333 | pub(crate) fn generic_predicates_query( |
322 | db: &impl HirDatabase, | 334 | db: &impl HirDatabase, |