diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-21 12:50:12 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-21 12:50:12 +0000 |
commit | 1f61915bde4c5d8d4fe2e9b8dfa9445008730b79 (patch) | |
tree | a6fd0b6ad8b6c87d28e6e1b36bb9b2fbae2c1b09 /crates/ra_hir/src/expr.rs | |
parent | 612a72fc4ea4376920f2a7da7b3c334227c1716c (diff) | |
parent | c37d1c5b381365ce2d07dfe4b871e43995ccea2d (diff) |
Merge #2337
2337: Move resolver to hir_def r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 33 |
1 files changed, 4 insertions, 29 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 869879bdf..6b703d8b4 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_def::path::known; | 5 | use hir_def::{path::known, resolver::HasResolver}; |
6 | use hir_expand::diagnostics::DiagnosticSink; | 6 | use hir_expand::diagnostics::DiagnosticSink; |
7 | use ra_syntax::ast; | 7 | use ra_syntax::ast; |
8 | use ra_syntax::AstPtr; | 8 | use ra_syntax::AstPtr; |
@@ -11,9 +11,8 @@ use rustc_hash::FxHashSet; | |||
11 | use crate::{ | 11 | use crate::{ |
12 | db::HirDatabase, | 12 | db::HirDatabase, |
13 | diagnostics::{MissingFields, MissingOkInTailExpr}, | 13 | diagnostics::{MissingFields, MissingOkInTailExpr}, |
14 | resolve::HasResolver, | ||
15 | ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, | 14 | ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, |
16 | Adt, DefWithBody, Function, HasBody, Name, Path, Resolver, | 15 | Adt, Function, Name, Path, |
17 | }; | 16 | }; |
18 | 17 | ||
19 | pub use hir_def::{ | 18 | pub use hir_def::{ |
@@ -27,30 +26,6 @@ pub use hir_def::{ | |||
27 | }, | 26 | }, |
28 | }; | 27 | }; |
29 | 28 | ||
30 | // needs arbitrary_self_types to be a method... or maybe move to the def? | ||
31 | pub(crate) fn resolver_for_expr( | ||
32 | db: &impl HirDatabase, | ||
33 | owner: DefWithBody, | ||
34 | expr_id: ExprId, | ||
35 | ) -> Resolver { | ||
36 | let scopes = owner.expr_scopes(db); | ||
37 | resolver_for_scope(db, owner, scopes.scope_for(expr_id)) | ||
38 | } | ||
39 | |||
40 | pub(crate) fn resolver_for_scope( | ||
41 | db: &impl HirDatabase, | ||
42 | owner: DefWithBody, | ||
43 | scope_id: Option<ScopeId>, | ||
44 | ) -> Resolver { | ||
45 | let mut r = owner.resolver(db); | ||
46 | let scopes = owner.expr_scopes(db); | ||
47 | let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>(); | ||
48 | for scope in scope_chain.into_iter().rev() { | ||
49 | r = r.push_expr_scope(owner, Arc::clone(&scopes), scope); | ||
50 | } | ||
51 | r | ||
52 | } | ||
53 | |||
54 | pub(crate) struct ExprValidator<'a, 'b: 'a> { | 29 | pub(crate) struct ExprValidator<'a, 'b: 'a> { |
55 | func: Function, | 30 | func: Function, |
56 | infer: Arc<InferenceResult>, | 31 | infer: Arc<InferenceResult>, |
@@ -146,13 +121,13 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
146 | 121 | ||
147 | let std_result_path = known::std_result_result(); | 122 | let std_result_path = known::std_result_result(); |
148 | 123 | ||
149 | let resolver = self.func.resolver(db); | 124 | let resolver = self.func.id.resolver(db); |
150 | let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) { | 125 | let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) { |
151 | Some(it) => it, | 126 | Some(it) => it, |
152 | _ => return, | 127 | _ => return, |
153 | }; | 128 | }; |
154 | 129 | ||
155 | let std_result_ctor = TypeCtor::Adt(Adt::Enum(std_result_enum)); | 130 | let std_result_ctor = TypeCtor::Adt(Adt::Enum(std_result_enum.into())); |
156 | let params = match &mismatch.expected { | 131 | let params = match &mismatch.expected { |
157 | Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters, | 132 | Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters, |
158 | _ => return, | 133 | _ => return, |