diff options
author | Seivan Heidari <[email protected]> | 2019-11-14 22:20:27 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-14 22:20:27 +0000 |
commit | c622413bc72ea56d5f62a16788d897cb61eca948 (patch) | |
tree | 9de3dbe8b5c935ed168efac4e70770e54fbe0714 /crates/ra_hir/src/code_model.rs | |
parent | 0525778a3ad590492b51cc11085d815f9bb8f92b (diff) | |
parent | bbb022d3999b3038549ec6c309efb065231c896a (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 2fd4ccb10..962d5a8c1 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -8,6 +8,7 @@ use std::sync::Arc; | |||
8 | 8 | ||
9 | use hir_def::{ | 9 | use hir_def::{ |
10 | adt::VariantData, | 10 | adt::VariantData, |
11 | body::scope::ExprScopes, | ||
11 | builtin_type::BuiltinType, | 12 | builtin_type::BuiltinType, |
12 | type_ref::{Mutability, TypeRef}, | 13 | type_ref::{Mutability, TypeRef}, |
13 | CrateModuleId, LocalEnumVariantId, LocalStructFieldId, ModuleId, UnionId, | 14 | CrateModuleId, LocalEnumVariantId, LocalStructFieldId, ModuleId, UnionId, |
@@ -539,6 +540,7 @@ pub trait HasBody: Copy { | |||
539 | fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult>; | 540 | fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult>; |
540 | fn body(self, db: &impl HirDatabase) -> Arc<Body>; | 541 | fn body(self, db: &impl HirDatabase) -> Arc<Body>; |
541 | fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap>; | 542 | fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap>; |
543 | fn expr_scopes(self, db: &impl HirDatabase) -> Arc<ExprScopes>; | ||
542 | } | 544 | } |
543 | 545 | ||
544 | impl<T> HasBody for T | 546 | impl<T> HasBody for T |
@@ -550,11 +552,15 @@ where | |||
550 | } | 552 | } |
551 | 553 | ||
552 | fn body(self, db: &impl HirDatabase) -> Arc<Body> { | 554 | fn body(self, db: &impl HirDatabase) -> Arc<Body> { |
553 | db.body(self.into()) | 555 | self.into().body(db) |
554 | } | 556 | } |
555 | 557 | ||
556 | fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { | 558 | fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { |
557 | db.body_with_source_map(self.into()).1 | 559 | self.into().body_source_map(db) |
560 | } | ||
561 | |||
562 | fn expr_scopes(self, db: &impl HirDatabase) -> Arc<ExprScopes> { | ||
563 | self.into().expr_scopes(db) | ||
558 | } | 564 | } |
559 | } | 565 | } |
560 | 566 | ||
@@ -564,11 +570,15 @@ impl HasBody for DefWithBody { | |||
564 | } | 570 | } |
565 | 571 | ||
566 | fn body(self, db: &impl HirDatabase) -> Arc<Body> { | 572 | fn body(self, db: &impl HirDatabase) -> Arc<Body> { |
567 | db.body(self) | 573 | db.body(self.into()) |
568 | } | 574 | } |
569 | 575 | ||
570 | fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { | 576 | fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { |
571 | db.body_with_source_map(self).1 | 577 | db.body_with_source_map(self.into()).1 |
578 | } | ||
579 | |||
580 | fn expr_scopes(self, db: &impl HirDatabase) -> Arc<ExprScopes> { | ||
581 | db.expr_scopes(self.into()) | ||
572 | } | 582 | } |
573 | } | 583 | } |
574 | 584 | ||
@@ -662,11 +672,11 @@ impl Function { | |||
662 | } | 672 | } |
663 | 673 | ||
664 | pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { | 674 | pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { |
665 | db.body_with_source_map(self.into()).1 | 675 | db.body_with_source_map(self.id.into()).1 |
666 | } | 676 | } |
667 | 677 | ||
668 | pub fn body(self, db: &impl HirDatabase) -> Arc<Body> { | 678 | pub fn body(self, db: &impl HirDatabase) -> Arc<Body> { |
669 | db.body(self.into()) | 679 | db.body(self.id.into()) |
670 | } | 680 | } |
671 | 681 | ||
672 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | 682 | pub fn ty(self, db: &impl HirDatabase) -> Ty { |
@@ -1079,7 +1089,7 @@ pub struct Local { | |||
1079 | 1089 | ||
1080 | impl Local { | 1090 | impl Local { |
1081 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { | 1091 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { |
1082 | let body = db.body(self.parent); | 1092 | let body = self.parent.body(db); |
1083 | match &body[self.pat_id] { | 1093 | match &body[self.pat_id] { |
1084 | Pat::Bind { name, .. } => Some(name.clone()), | 1094 | Pat::Bind { name, .. } => Some(name.clone()), |
1085 | _ => None, | 1095 | _ => None, |
@@ -1091,7 +1101,7 @@ impl Local { | |||
1091 | } | 1101 | } |
1092 | 1102 | ||
1093 | pub fn is_mut(self, db: &impl HirDatabase) -> bool { | 1103 | pub fn is_mut(self, db: &impl HirDatabase) -> bool { |
1094 | let body = db.body(self.parent); | 1104 | let body = self.parent.body(db); |
1095 | match &body[self.pat_id] { | 1105 | match &body[self.pat_id] { |
1096 | Pat::Bind { mode, .. } => match mode { | 1106 | Pat::Bind { mode, .. } => match mode { |
1097 | BindingAnnotation::Mutable | BindingAnnotation::RefMut => true, | 1107 | BindingAnnotation::Mutable | BindingAnnotation::RefMut => true, |
@@ -1115,7 +1125,7 @@ impl Local { | |||
1115 | } | 1125 | } |
1116 | 1126 | ||
1117 | pub fn source(self, db: &impl HirDatabase) -> Source<Either<ast::BindPat, ast::SelfParam>> { | 1127 | pub fn source(self, db: &impl HirDatabase) -> Source<Either<ast::BindPat, ast::SelfParam>> { |
1118 | let (_body, source_map) = db.body_with_source_map(self.parent); | 1128 | let source_map = self.parent.body_source_map(db); |
1119 | let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... | 1129 | let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... |
1120 | let root = src.file_syntax(db); | 1130 | let root = src.file_syntax(db); |
1121 | src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) | 1131 | src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) |