mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 17:07:26 +00:00
internal: Remove PathResolution::AssocItem
This commit is contained in:
parent
a1d684e951
commit
c290e68ff9
7 changed files with 28 additions and 36 deletions
|
@ -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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(_)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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(_) => (),
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue