aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer/path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/infer/path.rs')
-rw-r--r--crates/ra_hir_ty/src/infer/path.rs25
1 files changed, 13 insertions, 12 deletions
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs
index 37db005ea..3bae0ca6c 100644
--- a/crates/ra_hir_ty/src/infer/path.rs
+++ b/crates/ra_hir_ty/src/infer/path.rs
@@ -32,21 +32,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
32 path: &Path, 32 path: &Path,
33 id: ExprOrPatId, 33 id: ExprOrPatId,
34 ) -> Option<Ty> { 34 ) -> Option<Ty> {
35 let (value, self_subst) = if let PathKind::Type(type_ref) = &path.kind { 35 let (value, self_subst) = if let PathKind::Type(type_ref) = path.kind() {
36 if path.segments.is_empty() { 36 if path.segments().is_empty() {
37 // This can't actually happen syntax-wise 37 // This can't actually happen syntax-wise
38 return None; 38 return None;
39 } 39 }
40 let ty = self.make_ty(type_ref); 40 let ty = self.make_ty(type_ref);
41 let remaining_segments_for_ty = &path.segments[..path.segments.len() - 1]; 41 let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1);
42 let ty = Ty::from_type_relative_path(self.db, resolver, ty, remaining_segments_for_ty); 42 let ty = Ty::from_type_relative_path(self.db, resolver, ty, remaining_segments_for_ty);
43 self.resolve_ty_assoc_item( 43 self.resolve_ty_assoc_item(
44 ty, 44 ty,
45 &path.segments.last().expect("path had at least one segment").name, 45 &path.segments().last().expect("path had at least one segment").name,
46 id, 46 id,
47 )? 47 )?
48 } else { 48 } else {
49 let value_or_partial = resolver.resolve_path_in_value_ns(self.db, &path)?; 49 let value_or_partial = resolver.resolve_path_in_value_ns(self.db, path.mod_path())?;
50 50
51 match value_or_partial { 51 match value_or_partial {
52 ResolveValueResult::ValueNs(it) => (it, None), 52 ResolveValueResult::ValueNs(it) => (it, None),
@@ -85,13 +85,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
85 remaining_index: usize, 85 remaining_index: usize,
86 id: ExprOrPatId, 86 id: ExprOrPatId,
87 ) -> Option<(ValueNs, Option<Substs>)> { 87 ) -> Option<(ValueNs, Option<Substs>)> {
88 assert!(remaining_index < path.segments.len()); 88 assert!(remaining_index < path.segments().len());
89 // there may be more intermediate segments between the resolved one and 89 // there may be more intermediate segments between the resolved one and
90 // the end. Only the last segment needs to be resolved to a value; from 90 // the end. Only the last segment needs to be resolved to a value; from
91 // the segments before that, we need to get either a type or a trait ref. 91 // the segments before that, we need to get either a type or a trait ref.
92 92
93 let resolved_segment = &path.segments[remaining_index - 1]; 93 let resolved_segment = path.segments().get(remaining_index - 1).unwrap();
94 let remaining_segments = &path.segments[remaining_index..]; 94 let remaining_segments = path.segments().skip(remaining_index);
95 let is_before_last = remaining_segments.len() == 1; 95 let is_before_last = remaining_segments.len() == 1;
96 96
97 match (def, is_before_last) { 97 match (def, is_before_last) {
@@ -112,7 +112,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
112 // trait but it's not the last segment, so the next segment 112 // trait but it's not the last segment, so the next segment
113 // should resolve to an associated type of that trait (e.g. `<T 113 // should resolve to an associated type of that trait (e.g. `<T
114 // as Iterator>::Item::default`) 114 // as Iterator>::Item::default`)
115 let remaining_segments_for_ty = &remaining_segments[..remaining_segments.len() - 1]; 115 let remaining_segments_for_ty =
116 remaining_segments.take(remaining_segments.len() - 1);
116 let ty = Ty::from_partly_resolved_hir_path( 117 let ty = Ty::from_partly_resolved_hir_path(
117 self.db, 118 self.db,
118 &self.resolver, 119 &self.resolver,
@@ -138,7 +139,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
138 fn resolve_trait_assoc_item( 139 fn resolve_trait_assoc_item(
139 &mut self, 140 &mut self,
140 trait_ref: TraitRef, 141 trait_ref: TraitRef,
141 segment: &PathSegment, 142 segment: PathSegment<'_>,
142 id: ExprOrPatId, 143 id: ExprOrPatId,
143 ) -> Option<(ValueNs, Option<Substs>)> { 144 ) -> Option<(ValueNs, Option<Substs>)> {
144 let trait_ = trait_ref.trait_; 145 let trait_ = trait_ref.trait_;
@@ -150,7 +151,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
150 .map(|(_name, id)| (*id).into()) 151 .map(|(_name, id)| (*id).into())
151 .find_map(|item| match item { 152 .find_map(|item| match item {
152 AssocItemId::FunctionId(func) => { 153 AssocItemId::FunctionId(func) => {
153 if segment.name == self.db.function_data(func).name { 154 if segment.name == &self.db.function_data(func).name {
154 Some(AssocItemId::FunctionId(func)) 155 Some(AssocItemId::FunctionId(func))
155 } else { 156 } else {
156 None 157 None
@@ -158,7 +159,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
158 } 159 }
159 160
160 AssocItemId::ConstId(konst) => { 161 AssocItemId::ConstId(konst) => {
161 if self.db.const_data(konst).name.as_ref().map_or(false, |n| n == &segment.name) 162 if self.db.const_data(konst).name.as_ref().map_or(false, |n| n == segment.name)
162 { 163 {
163 Some(AssocItemId::ConstId(konst)) 164 Some(AssocItemId::ConstId(konst))
164 } else { 165 } else {