about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-04-01 18:32:05 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-04-01 18:32:05 +0200
commitc290e68ff92db53adbbee33f0031aa174a0f5c8d (patch)
treeaaf26a502a96a3e603e8c267434669ecd74093d1
parenta1d684e95130cca21fc78f1642b02811ad09db15 (diff)
downloadrust-c290e68ff92db53adbbee33f0031aa174a0f5c8d.tar.gz
rust-c290e68ff92db53adbbee33f0031aa174a0f5c8d.zip
internal: Remove `PathResolution::AssocItem`
-rw-r--r--crates/hir/src/semantics.rs11
-rw-r--r--crates/hir/src/source_analyzer.rs9
-rw-r--r--crates/ide/src/signature_help.rs3
-rw-r--r--crates/ide_assists/src/handlers/inline_call.rs1
-rw-r--r--crates/ide_db/src/defs.rs8
-rw-r--r--crates/ide_db/src/path_transform.rs6
-rw-r--r--crates/ide_ssr/src/resolving.rs26
7 files changed, 28 insertions, 36 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 8a700027a3a..246b93723b3 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -30,9 +30,9 @@ use crate::{
     db::HirDatabase,
     semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
     source_analyzer::{resolve_hir_path, SourceAnalyzer},
-    Access, AssocItem, BuiltinAttr, Callable, ConstParam, Crate, Field, Function, HasSource,
-    HirFileId, Impl, InFile, Label, LifetimeParam, Local, Macro, Module, ModuleDef, Name, Path,
-    ScopeDef, ToolModule, Trait, Type, TypeAlias, TypeParam, VariantDef,
+    Access, BuiltinAttr, Callable, ConstParam, Crate, Field, Function, HasSource, HirFileId, Impl,
+    InFile, Label, LifetimeParam, Local, Macro, Module, ModuleDef, Name, Path, ScopeDef,
+    ToolModule, Trait, Type, TypeAlias, TypeParam, VariantDef,
 };
 
 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -46,7 +46,6 @@ pub enum PathResolution {
     /// A const parameter
     ConstParam(ConstParam),
     SelfType(Impl),
-    AssocItem(AssocItem),
     BuiltinAttr(BuiltinAttr),
     ToolModule(ToolModule),
 }
@@ -76,10 +75,6 @@ impl PathResolution {
             | PathResolution::ConstParam(_) => None,
             PathResolution::TypeParam(param) => Some(TypeNs::GenericParam((*param).into())),
             PathResolution::SelfType(impl_def) => Some(TypeNs::SelfType((*impl_def).into())),
-            PathResolution::AssocItem(AssocItem::Const(_) | AssocItem::Function(_)) => None,
-            PathResolution::AssocItem(AssocItem::TypeAlias(alias)) => {
-                Some(TypeNs::TypeAliasId((*alias).into()))
-            }
         }
     }
 }
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index f9184434273..6f5908ceb70 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -40,8 +40,9 @@ use syntax::{
 };
 
 use crate::{
-    db::HirDatabase, semantics::PathResolution, Adt, BuiltinAttr, BuiltinType, Const, Field,
-    Function, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias, Variant,
+    db::HirDatabase, semantics::PathResolution, Adt, AssocItem, BuiltinAttr, BuiltinType, Const,
+    Field, Function, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias,
+    Variant,
 };
 use base_db::CrateId;
 
@@ -302,7 +303,7 @@ impl SourceAnalyzer {
             let expr_id = self.expr_id(db, &path_expr.into())?;
             let infer = self.infer.as_ref()?;
             if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
-                return Some(PathResolution::AssocItem(assoc.into()));
+                return Some(PathResolution::Def(AssocItem::from(assoc).into()));
             }
             if let Some(VariantId::EnumVariantId(variant)) =
                 infer.variant_resolution_for_expr(expr_id)
@@ -313,7 +314,7 @@ impl SourceAnalyzer {
         } else if let Some(path_pat) = parent().and_then(ast::PathPat::cast) {
             let pat_id = self.pat_id(&path_pat.into())?;
             if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
-                return Some(PathResolution::AssocItem(assoc.into()));
+                return Some(PathResolution::Def(AssocItem::from(assoc).into()));
             }
             if let Some(VariantId::EnumVariantId(variant)) =
                 self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs
index f33b09ed578..6dc8b3046cc 100644
--- a/crates/ide/src/signature_help.rs
+++ b/crates/ide/src/signature_help.rs
@@ -198,9 +198,6 @@ fn signature_help_for_generics(
             | hir::PathResolution::Def(hir::ModuleDef::Macro(_))
             | hir::PathResolution::Def(hir::ModuleDef::Module(_))
             | hir::PathResolution::Def(hir::ModuleDef::Static(_)) => return None,
-            hir::PathResolution::AssocItem(hir::AssocItem::Function(it)) => it.into(),
-            hir::PathResolution::AssocItem(hir::AssocItem::TypeAlias(it)) => it.into(),
-            hir::PathResolution::AssocItem(hir::AssocItem::Const(_)) => return None,
             hir::PathResolution::BuiltinAttr(_)
             | hir::PathResolution::ToolModule(_)
             | hir::PathResolution::Local(_)
diff --git a/crates/ide_assists/src/handlers/inline_call.rs b/crates/ide_assists/src/handlers/inline_call.rs
index 5a28cbcc233..af2cb332e5a 100644
--- a/crates/ide_assists/src/handlers/inline_call.rs
+++ b/crates/ide_assists/src/handlers/inline_call.rs
@@ -185,7 +185,6 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
             }?;
             let function = match ctx.sema.resolve_path(&path)? {
                 PathResolution::Def(hir::ModuleDef::Function(f)) => f,
-                PathResolution::AssocItem(hir::AssocItem::Function(f)) => f,
                 _ => return None,
             };
             (function, format!("Inline `{}`", path))
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs
index 36457a5364f..34b557e21ea 100644
--- a/crates/ide_db/src/defs.rs
+++ b/crates/ide_db/src/defs.rs
@@ -482,14 +482,6 @@ impl From<PathResolution> for Definition {
     fn from(path_resolution: PathResolution) -> Self {
         match path_resolution {
             PathResolution::Def(def) => def.into(),
-            PathResolution::AssocItem(item) => {
-                let def: ModuleDef = match item {
-                    hir::AssocItem::Function(it) => it.into(),
-                    hir::AssocItem::Const(it) => it.into(),
-                    hir::AssocItem::TypeAlias(it) => it.into(),
-                };
-                def.into()
-            }
             PathResolution::Local(local) => Definition::Local(local),
             PathResolution::TypeParam(par) => Definition::GenericParam(par.into()),
             PathResolution::ConstParam(par) => Definition::GenericParam(par.into()),
diff --git a/crates/ide_db/src/path_transform.rs b/crates/ide_db/src/path_transform.rs
index 15bd9a8c9c1..61b2c3f3b8b 100644
--- a/crates/ide_db/src/path_transform.rs
+++ b/crates/ide_db/src/path_transform.rs
@@ -2,7 +2,7 @@
 
 use crate::helpers::mod_path_to_ast;
 use either::Either;
-use hir::{HirDisplay, SemanticsScope};
+use hir::{AsAssocItem, HirDisplay, SemanticsScope};
 use rustc_hash::FxHashMap;
 use syntax::{
     ast::{self, AstNode},
@@ -197,7 +197,7 @@ impl<'a> Ctx<'a> {
                     }
                 }
             }
-            hir::PathResolution::Def(def) => {
+            hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => {
                 if let hir::ModuleDef::Trait(_) = def {
                     if matches!(path.segment()?.kind()?, ast::PathSegmentKind::Type { .. }) {
                         // `speculative_resolve` resolves segments like `<T as
@@ -222,7 +222,7 @@ impl<'a> Ctx<'a> {
             hir::PathResolution::Local(_)
             | hir::PathResolution::ConstParam(_)
             | hir::PathResolution::SelfType(_)
-            | hir::PathResolution::AssocItem(_)
+            | hir::PathResolution::Def(_)
             | hir::PathResolution::BuiltinAttr(_)
             | hir::PathResolution::ToolModule(_) => (),
         }
diff --git a/crates/ide_ssr/src/resolving.rs b/crates/ide_ssr/src/resolving.rs
index d9b40608b82..84bf792fe07 100644
--- a/crates/ide_ssr/src/resolving.rs
+++ b/crates/ide_ssr/src/resolving.rs
@@ -2,6 +2,7 @@
 
 use crate::errors::error;
 use crate::{parsing, SsrError};
+use hir::AsAssocItem;
 use ide_db::base_db::FilePosition;
 use parsing::Placeholder;
 use rustc_hash::FxHashMap;
@@ -82,14 +83,17 @@ impl Resolver<'_, '_> {
             .filter_map(|(path_node, resolved)| {
                 if let Some(grandparent) = path_node.parent().and_then(|parent| parent.parent()) {
                     if let Some(call_expr) = ast::CallExpr::cast(grandparent.clone()) {
-                        if let hir::PathResolution::AssocItem(hir::AssocItem::Function(function)) =
+                        if let hir::PathResolution::Def(hir::ModuleDef::Function(function)) =
                             resolved.resolution
                         {
-                            let qualifier_type = self.resolution_scope.qualifier_type(path_node);
-                            return Some((
-                                grandparent,
-                                UfcsCallInfo { call_expr, function, qualifier_type },
-                            ));
+                            if function.as_assoc_item(self.resolution_scope.scope.db).is_some() {
+                                let qualifier_type =
+                                    self.resolution_scope.qualifier_type(path_node);
+                                return Some((
+                                    grandparent,
+                                    UfcsCallInfo { call_expr, function, qualifier_type },
+                                ));
+                            }
                         }
                     }
                 }
@@ -162,7 +166,9 @@ impl Resolver<'_, '_> {
 
     fn ok_to_use_path_resolution(&self, resolution: &hir::PathResolution) -> bool {
         match resolution {
-            hir::PathResolution::AssocItem(hir::AssocItem::Function(function)) => {
+            hir::PathResolution::Def(hir::ModuleDef::Function(function))
+                if function.as_assoc_item(self.resolution_scope.scope.db).is_some() =>
+            {
                 if function.self_param(self.resolution_scope.scope.db).is_some() {
                     // If we don't use this path resolution, then we won't be able to match method
                     // calls. e.g. `Foo::bar($s)` should match `x.bar()`.
@@ -172,7 +178,9 @@ impl Resolver<'_, '_> {
                     false
                 }
             }
-            hir::PathResolution::AssocItem(_) => {
+            hir::PathResolution::Def(
+                def @ (hir::ModuleDef::Const(_) | hir::ModuleDef::TypeAlias(_)),
+            ) if def.as_assoc_item(self.resolution_scope.scope.db).is_some() => {
                 // Not a function. Could be a constant or an associated type.
                 cov_mark::hit!(replace_associated_trait_constant);
                 false
@@ -229,7 +237,7 @@ impl<'db> ResolutionScope<'db> {
                 |assoc_item| {
                     let item_name = assoc_item.name(self.scope.db)?;
                     if item_name.to_smol_str().as_str() == name.text() {
-                        Some(hir::PathResolution::AssocItem(assoc_item))
+                        Some(hir::PathResolution::Def(assoc_item.into()))
                     } else {
                         None
                     }