aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/adt.rs14
-rw-r--r--crates/ra_hir/src/lib.rs1
-rw-r--r--crates/ra_hir/src/ty.rs5
3 files changed, 17 insertions, 3 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 03770ed7d..e65f8deb8 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -124,6 +124,15 @@ pub struct StructField {
124 ty: Ty, 124 ty: Ty,
125} 125}
126 126
127impl StructField {
128 pub fn name(&self) -> SmolStr {
129 self.name.clone()
130 }
131 pub fn ty(&self) -> Ty {
132 self.ty.clone()
133 }
134}
135
127/// Fields of an enum variant or struct 136/// Fields of an enum variant or struct
128#[derive(Debug, Clone, PartialEq, Eq)] 137#[derive(Debug, Clone, PartialEq, Eq)]
129pub enum VariantData { 138pub enum VariantData {
@@ -168,7 +177,10 @@ impl VariantData {
168 } 177 }
169 178
170 pub(crate) fn get_field_ty(&self, field_name: &str) -> Option<Ty> { 179 pub(crate) fn get_field_ty(&self, field_name: &str) -> Option<Ty> {
171 self.fields().iter().find(|f| f.name == field_name).map(|f| f.ty.clone()) 180 self.fields()
181 .iter()
182 .find(|f| f.name == field_name)
183 .map(|f| f.ty.clone())
172 } 184 }
173 185
174 pub fn fields(&self) -> &[StructField] { 186 pub fn fields(&self) -> &[StructField] {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 796970d8a..68fdbb7ea 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -44,6 +44,7 @@ pub use self::{
44 module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, 44 module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution},
45 function::{Function, FnScopes}, 45 function::{Function, FnScopes},
46 adt::{Struct, Enum}, 46 adt::{Struct, Enum},
47 ty::Ty,
47}; 48};
48 49
49pub use self::function::FnSignatureInfo; 50pub use self::function::FnSignatureInfo;
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index f931f3c87..83da13f1a 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -574,7 +574,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
574 match receiver_ty { 574 match receiver_ty {
575 Ty::Tuple(fields) => { 575 Ty::Tuple(fields) => {
576 let i = text.parse::<usize>().ok(); 576 let i = text.parse::<usize>().ok();
577 i.and_then(|i| fields.get(i).cloned()).unwrap_or(Ty::Unknown) 577 i.and_then(|i| fields.get(i).cloned())
578 .unwrap_or(Ty::Unknown)
578 } 579 }
579 Ty::Adt { def_id, .. } => { 580 Ty::Adt { def_id, .. } => {
580 let field_ty = match def_id.resolve(self.db)? { 581 let field_ty = match def_id.resolve(self.db)? {
@@ -589,7 +590,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
589 } else { 590 } else {
590 Ty::Unknown 591 Ty::Unknown
591 } 592 }
592 }, 593 }
593 ast::Expr::TryExpr(e) => { 594 ast::Expr::TryExpr(e) => {
594 let _inner_ty = if let Some(e) = e.expr() { 595 let _inner_ty = if let Some(e) = e.expr() {
595 self.infer_expr(e)? 596 self.infer_expr(e)?