aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/source_analyzer.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index 626c3078a..bed3fa50f 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -222,8 +222,9 @@ impl SourceAnalyzer {
222 db: &dyn HirDatabase, 222 db: &dyn HirDatabase,
223 path: &ast::Path, 223 path: &ast::Path,
224 ) -> Option<PathResolution> { 224 ) -> Option<PathResolution> {
225 let parent = || path.syntax().parent();
225 let mut prefer_value_ns = false; 226 let mut prefer_value_ns = false;
226 if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) { 227 if let Some(path_expr) = parent().and_then(ast::PathExpr::cast) {
227 let expr_id = self.expr_id(db, &path_expr.into())?; 228 let expr_id = self.expr_id(db, &path_expr.into())?;
228 let infer = self.infer.as_ref()?; 229 let infer = self.infer.as_ref()?;
229 if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) { 230 if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
@@ -237,7 +238,7 @@ impl SourceAnalyzer {
237 prefer_value_ns = true; 238 prefer_value_ns = true;
238 } 239 }
239 240
240 if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) { 241 if let Some(path_pat) = parent().and_then(ast::PathPat::cast) {
241 let pat_id = self.pat_id(&path_pat.into())?; 242 let pat_id = self.pat_id(&path_pat.into())?;
242 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) { 243 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
243 return Some(PathResolution::AssocItem(assoc.into())); 244 return Some(PathResolution::AssocItem(assoc.into()));
@@ -249,7 +250,7 @@ impl SourceAnalyzer {
249 } 250 }
250 } 251 }
251 252
252 if let Some(rec_lit) = path.syntax().parent().and_then(ast::RecordExpr::cast) { 253 if let Some(rec_lit) = parent().and_then(ast::RecordExpr::cast) {
253 let expr_id = self.expr_id(db, &rec_lit.into())?; 254 let expr_id = self.expr_id(db, &rec_lit.into())?;
254 if let Some(VariantId::EnumVariantId(variant)) = 255 if let Some(VariantId::EnumVariantId(variant)) =
255 self.infer.as_ref()?.variant_resolution_for_expr(expr_id) 256 self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
@@ -258,8 +259,12 @@ impl SourceAnalyzer {
258 } 259 }
259 } 260 }
260 261
261 if let Some(rec_pat) = path.syntax().parent().and_then(ast::RecordPat::cast) { 262 if let Some(pat) = parent()
262 let pat_id = self.pat_id(&rec_pat.into())?; 263 .and_then(ast::RecordPat::cast)
264 .map(ast::Pat::from)
265 .or_else(|| parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from))
266 {
267 let pat_id = self.pat_id(&pat)?;
263 if let Some(VariantId::EnumVariantId(variant)) = 268 if let Some(VariantId::EnumVariantId(variant)) =
264 self.infer.as_ref()?.variant_resolution_for_pat(pat_id) 269 self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
265 { 270 {
@@ -272,7 +277,7 @@ impl SourceAnalyzer {
272 277
273 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we 278 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we
274 // trying to resolve foo::bar. 279 // trying to resolve foo::bar.
275 if let Some(outer_path) = path.syntax().parent().and_then(ast::Path::cast) { 280 if let Some(outer_path) = parent().and_then(ast::Path::cast) {
276 if let Some(qualifier) = outer_path.qualifier() { 281 if let Some(qualifier) = outer_path.qualifier() {
277 if path == &qualifier { 282 if path == &qualifier {
278 return resolve_hir_path_qualifier(db, &self.resolver, &hir_path); 283 return resolve_hir_path_qualifier(db, &self.resolver, &hir_path);