diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-30 15:23:21 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-30 15:23:21 +0000 |
commit | f408ff50130eae0eb56e7f9668e9df39f7baa6dd (patch) | |
tree | 099e32b0fb1f94bef58d6d9a23d45d2e8b890ae1 /crates/hir/src | |
parent | 557c1e36ddbb19cc76f7a1f04d1b327942aafcb9 (diff) | |
parent | e3eeccf8ef2029bb54ba05af420a65b429763477 (diff) |
Merge #7483
7483: Classify function calls as functions when shadowed by types r=matklad a=Veykril
Fixes #7479
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/source_analyzer.rs | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 30a8e513d..626c3078a 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs | |||
@@ -222,16 +222,19 @@ 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 mut prefer_value_ns = false; | ||
225 | if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) { | 226 | if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) { |
226 | let expr_id = self.expr_id(db, &path_expr.into())?; | 227 | let expr_id = self.expr_id(db, &path_expr.into())?; |
227 | if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) { | 228 | let infer = self.infer.as_ref()?; |
229 | if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) { | ||
228 | return Some(PathResolution::AssocItem(assoc.into())); | 230 | return Some(PathResolution::AssocItem(assoc.into())); |
229 | } | 231 | } |
230 | if let Some(VariantId::EnumVariantId(variant)) = | 232 | if let Some(VariantId::EnumVariantId(variant)) = |
231 | self.infer.as_ref()?.variant_resolution_for_expr(expr_id) | 233 | infer.variant_resolution_for_expr(expr_id) |
232 | { | 234 | { |
233 | return Some(PathResolution::Def(ModuleDef::Variant(variant.into()))); | 235 | return Some(PathResolution::Def(ModuleDef::Variant(variant.into()))); |
234 | } | 236 | } |
237 | prefer_value_ns = true; | ||
235 | } | 238 | } |
236 | 239 | ||
237 | if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) { | 240 | if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) { |
@@ -277,7 +280,7 @@ impl SourceAnalyzer { | |||
277 | } | 280 | } |
278 | } | 281 | } |
279 | 282 | ||
280 | resolve_hir_path(db, &self.resolver, &hir_path) | 283 | resolve_hir_path_(db, &self.resolver, &hir_path, prefer_value_ns) |
281 | } | 284 | } |
282 | 285 | ||
283 | pub(crate) fn record_literal_missing_fields( | 286 | pub(crate) fn record_literal_missing_fields( |
@@ -447,12 +450,22 @@ fn adjust( | |||
447 | .map(|(_ptr, scope)| *scope) | 450 | .map(|(_ptr, scope)| *scope) |
448 | } | 451 | } |
449 | 452 | ||
453 | #[inline] | ||
450 | pub(crate) fn resolve_hir_path( | 454 | pub(crate) fn resolve_hir_path( |
451 | db: &dyn HirDatabase, | 455 | db: &dyn HirDatabase, |
452 | resolver: &Resolver, | 456 | resolver: &Resolver, |
453 | path: &Path, | 457 | path: &Path, |
454 | ) -> Option<PathResolution> { | 458 | ) -> Option<PathResolution> { |
455 | let types = | 459 | resolve_hir_path_(db, resolver, path, false) |
460 | } | ||
461 | |||
462 | fn resolve_hir_path_( | ||
463 | db: &dyn HirDatabase, | ||
464 | resolver: &Resolver, | ||
465 | path: &Path, | ||
466 | prefer_value_ns: bool, | ||
467 | ) -> Option<PathResolution> { | ||
468 | let types = || { | ||
456 | resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty { | 469 | resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty { |
457 | TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), | 470 | TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), |
458 | TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }), | 471 | TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }), |
@@ -463,10 +476,11 @@ pub(crate) fn resolve_hir_path( | |||
463 | TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), | 476 | TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), |
464 | TypeNs::BuiltinType(it) => PathResolution::Def(it.into()), | 477 | TypeNs::BuiltinType(it) => PathResolution::Def(it.into()), |
465 | TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), | 478 | TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), |
466 | }); | 479 | }) |
480 | }; | ||
467 | 481 | ||
468 | let body_owner = resolver.body_owner(); | 482 | let body_owner = resolver.body_owner(); |
469 | let values = | 483 | let values = || { |
470 | resolver.resolve_path_in_value_ns_fully(db.upcast(), path.mod_path()).and_then(|val| { | 484 | resolver.resolve_path_in_value_ns_fully(db.upcast(), path.mod_path()).and_then(|val| { |
471 | let res = match val { | 485 | let res = match val { |
472 | ValueNs::LocalBinding(pat_id) => { | 486 | ValueNs::LocalBinding(pat_id) => { |
@@ -482,18 +496,25 @@ pub(crate) fn resolve_hir_path( | |||
482 | ValueNs::GenericParam(it) => PathResolution::ConstParam(it.into()), | 496 | ValueNs::GenericParam(it) => PathResolution::ConstParam(it.into()), |
483 | }; | 497 | }; |
484 | Some(res) | 498 | Some(res) |
485 | }); | 499 | }) |
500 | }; | ||
486 | 501 | ||
487 | let items = resolver | 502 | let items = || { |
488 | .resolve_module_path_in_items(db.upcast(), path.mod_path()) | 503 | resolver |
489 | .take_types() | 504 | .resolve_module_path_in_items(db.upcast(), path.mod_path()) |
490 | .map(|it| PathResolution::Def(it.into())); | 505 | .take_types() |
506 | .map(|it| PathResolution::Def(it.into())) | ||
507 | }; | ||
491 | 508 | ||
492 | types.or(values).or(items).or_else(|| { | 509 | let macros = || { |
493 | resolver | 510 | resolver |
494 | .resolve_path_as_macro(db.upcast(), path.mod_path()) | 511 | .resolve_path_as_macro(db.upcast(), path.mod_path()) |
495 | .map(|def| PathResolution::Macro(def.into())) | 512 | .map(|def| PathResolution::Macro(def.into())) |
496 | }) | 513 | }; |
514 | |||
515 | if prefer_value_ns { values().or_else(types) } else { types().or_else(values) } | ||
516 | .or_else(items) | ||
517 | .or_else(macros) | ||
497 | } | 518 | } |
498 | 519 | ||
499 | /// Resolves a path where we know it is a qualifier of another path. | 520 | /// Resolves a path where we know it is a qualifier of another path. |