diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 2 |
2 files changed, 10 insertions, 10 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index e1edf1bff..c759d4c8b 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -241,12 +241,12 @@ pub fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> { | |||
241 | 241 | ||
242 | #[derive(Clone, PartialEq, Eq, Debug)] | 242 | #[derive(Clone, PartialEq, Eq, Debug)] |
243 | pub struct InferenceResult { | 243 | pub struct InferenceResult { |
244 | type_for: FxHashMap<LocalSyntaxPtr, Ty>, | 244 | type_of: FxHashMap<LocalSyntaxPtr, Ty>, |
245 | } | 245 | } |
246 | 246 | ||
247 | impl InferenceResult { | 247 | impl InferenceResult { |
248 | pub fn type_of_node(&self, node: SyntaxNodeRef) -> Option<Ty> { | 248 | pub fn type_of_node(&self, node: SyntaxNodeRef) -> Option<Ty> { |
249 | self.type_for.get(&LocalSyntaxPtr::new(node)).cloned() | 249 | self.type_of.get(&LocalSyntaxPtr::new(node)).cloned() |
250 | } | 250 | } |
251 | } | 251 | } |
252 | 252 | ||
@@ -256,13 +256,13 @@ pub struct InferenceContext<'a, D: HirDatabase> { | |||
256 | scopes: Arc<FnScopes>, | 256 | scopes: Arc<FnScopes>, |
257 | module: Module, | 257 | module: Module, |
258 | // TODO unification tables... | 258 | // TODO unification tables... |
259 | type_for: FxHashMap<LocalSyntaxPtr, Ty>, | 259 | type_of: FxHashMap<LocalSyntaxPtr, Ty>, |
260 | } | 260 | } |
261 | 261 | ||
262 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 262 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { |
263 | fn new(db: &'a D, scopes: Arc<FnScopes>, module: Module) -> Self { | 263 | fn new(db: &'a D, scopes: Arc<FnScopes>, module: Module) -> Self { |
264 | InferenceContext { | 264 | InferenceContext { |
265 | type_for: FxHashMap::default(), | 265 | type_of: FxHashMap::default(), |
266 | db, | 266 | db, |
267 | scopes, | 267 | scopes, |
268 | module, | 268 | module, |
@@ -270,7 +270,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
270 | } | 270 | } |
271 | 271 | ||
272 | fn write_ty(&mut self, node: SyntaxNodeRef, ty: Ty) { | 272 | fn write_ty(&mut self, node: SyntaxNodeRef, ty: Ty) { |
273 | self.type_for.insert(LocalSyntaxPtr::new(node), ty); | 273 | self.type_of.insert(LocalSyntaxPtr::new(node), ty); |
274 | } | 274 | } |
275 | 275 | ||
276 | fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> Option<Ty> { | 276 | fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> Option<Ty> { |
@@ -299,7 +299,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
299 | // resolve locally | 299 | // resolve locally |
300 | let name = ctry!(ast_path.segment().and_then(|s| s.name_ref())); | 300 | let name = ctry!(ast_path.segment().and_then(|s| s.name_ref())); |
301 | if let Some(scope_entry) = self.scopes.resolve_local_name(name) { | 301 | if let Some(scope_entry) = self.scopes.resolve_local_name(name) { |
302 | let ty = ctry!(self.type_for.get(&scope_entry.ptr())); | 302 | let ty = ctry!(self.type_of.get(&scope_entry.ptr())); |
303 | return Ok(Some(ty.clone())); | 303 | return Ok(Some(ty.clone())); |
304 | }; | 304 | }; |
305 | }; | 305 | }; |
@@ -577,10 +577,10 @@ pub fn infer(db: &impl HirDatabase, function: Function) -> Cancelable<InferenceR | |||
577 | }; | 577 | }; |
578 | if let Some(type_ref) = param.type_ref() { | 578 | if let Some(type_ref) = param.type_ref() { |
579 | let ty = Ty::new(db, type_ref)?; | 579 | let ty = Ty::new(db, type_ref)?; |
580 | ctx.type_for.insert(LocalSyntaxPtr::new(pat.syntax()), ty); | 580 | ctx.type_of.insert(LocalSyntaxPtr::new(pat.syntax()), ty); |
581 | } else { | 581 | } else { |
582 | // TODO self param | 582 | // TODO self param |
583 | ctx.type_for | 583 | ctx.type_of |
584 | .insert(LocalSyntaxPtr::new(pat.syntax()), Ty::Unknown); | 584 | .insert(LocalSyntaxPtr::new(pat.syntax()), Ty::Unknown); |
585 | }; | 585 | }; |
586 | } | 586 | } |
@@ -596,6 +596,6 @@ pub fn infer(db: &impl HirDatabase, function: Function) -> Cancelable<InferenceR | |||
596 | // TODO 'resolve' the types: replace inference variables by their inferred results | 596 | // TODO 'resolve' the types: replace inference variables by their inferred results |
597 | 597 | ||
598 | Ok(InferenceResult { | 598 | Ok(InferenceResult { |
599 | type_for: ctx.type_for, | 599 | type_of: ctx.type_of, |
600 | }) | 600 | }) |
601 | } | 601 | } |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index e0458327a..021227749 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -26,7 +26,7 @@ fn infer_file(content: &str) -> String { | |||
26 | .unwrap() | 26 | .unwrap() |
27 | .unwrap(); | 27 | .unwrap(); |
28 | let inference_result = func.infer(&db).unwrap(); | 28 | let inference_result = func.infer(&db).unwrap(); |
29 | for (syntax_ptr, ty) in &inference_result.type_for { | 29 | for (syntax_ptr, ty) in &inference_result.type_of { |
30 | let node = syntax_ptr.resolve(&source_file); | 30 | let node = syntax_ptr.resolve(&source_file); |
31 | write!( | 31 | write!( |
32 | acc, | 32 | acc, |