diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-12 19:36:36 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-12 19:36:36 +0100 |
commit | 0f57564f78207946fdb09e0cddc21a55966b1bc5 (patch) | |
tree | e8aa2948b2bb301f453307c35311634cda5de43b /crates/ra_hir/src/resolve.rs | |
parent | 02ba107bbf24b1d09e61f76bb64b7355076744c4 (diff) | |
parent | bc59f83991a6444ff2f2364b0e942e8a82943b6d (diff) |
Merge #1266
1266: Chalk integration / method resolution fixes r=matklad a=flodiebold
- fix impl blocks with unresolved target trait being treated as inherent impls
- add traits from prelude for method resolution, and deduplicate them
- blacklist some traits from being considered in where clauses, namely `Send`, `Sync`, `Sized`, and the `Fn` traits. We don't handle these correctly yet for several reasons, and this makes us much less likely to run into cases where Chalk gets very slow (because these usually only happen if there is no solution, and that's more likely to happen for these traits).
- when there's an errored where clause, return just that one (since it will be always false anyway). This also makes things easier on Chalk ;)
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 707556ef8..2fb219908 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -3,7 +3,7 @@ use std::sync::Arc; | |||
3 | 3 | ||
4 | use ra_syntax::ast; | 4 | use ra_syntax::ast; |
5 | 5 | ||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::{FxHashMap, FxHashSet}; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | ModuleDef, Trait, | 9 | ModuleDef, Trait, |
@@ -193,19 +193,18 @@ impl Resolver { | |||
193 | names | 193 | names |
194 | } | 194 | } |
195 | 195 | ||
196 | pub(crate) fn traits_in_scope<'a>(&'a self) -> impl Iterator<Item = Trait> + 'a { | 196 | pub(crate) fn traits_in_scope(&self, db: &impl HirDatabase) -> FxHashSet<Trait> { |
197 | // FIXME prelude | 197 | let mut traits = FxHashSet::default(); |
198 | self.scopes | 198 | for scope in &self.scopes { |
199 | .iter() | 199 | if let Scope::ModuleScope(m) = scope { |
200 | .rev() | 200 | if let Some(prelude) = m.crate_def_map.prelude() { |
201 | .flat_map(|scope| { | 201 | let prelude_def_map = db.crate_def_map(prelude.krate); |
202 | match scope { | 202 | traits.extend(prelude_def_map[prelude.module_id].scope.traits()); |
203 | Scope::ModuleScope(m) => Some(m.crate_def_map[m.module_id].scope.traits()), | ||
204 | _ => None, | ||
205 | } | 203 | } |
206 | .into_iter() | 204 | traits.extend(m.crate_def_map[m.module_id].scope.traits()); |
207 | }) | 205 | } |
208 | .flatten() | 206 | } |
207 | traits | ||
209 | } | 208 | } |
210 | 209 | ||
211 | fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> { | 210 | fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> { |