mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Merge #11872
11872: internal: Remove `PathResolution::AssocItem` r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
ce8e028e9b
7 changed files with 28 additions and 36 deletions
|
@ -30,9 +30,9 @@ use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
|
semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
|
||||||
source_analyzer::{resolve_hir_path, SourceAnalyzer},
|
source_analyzer::{resolve_hir_path, SourceAnalyzer},
|
||||||
Access, AssocItem, BuiltinAttr, Callable, ConstParam, Crate, Field, Function, HasSource,
|
Access, BuiltinAttr, Callable, ConstParam, Crate, Field, Function, HasSource, HirFileId, Impl,
|
||||||
HirFileId, Impl, InFile, Label, LifetimeParam, Local, Macro, Module, ModuleDef, Name, Path,
|
InFile, Label, LifetimeParam, Local, Macro, Module, ModuleDef, Name, Path, ScopeDef,
|
||||||
ScopeDef, ToolModule, Trait, Type, TypeAlias, TypeParam, VariantDef,
|
ToolModule, Trait, Type, TypeAlias, TypeParam, VariantDef,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -46,7 +46,6 @@ pub enum PathResolution {
|
||||||
/// A const parameter
|
/// A const parameter
|
||||||
ConstParam(ConstParam),
|
ConstParam(ConstParam),
|
||||||
SelfType(Impl),
|
SelfType(Impl),
|
||||||
AssocItem(AssocItem),
|
|
||||||
BuiltinAttr(BuiltinAttr),
|
BuiltinAttr(BuiltinAttr),
|
||||||
ToolModule(ToolModule),
|
ToolModule(ToolModule),
|
||||||
}
|
}
|
||||||
|
@ -76,10 +75,6 @@ impl PathResolution {
|
||||||
| PathResolution::ConstParam(_) => None,
|
| PathResolution::ConstParam(_) => None,
|
||||||
PathResolution::TypeParam(param) => Some(TypeNs::GenericParam((*param).into())),
|
PathResolution::TypeParam(param) => Some(TypeNs::GenericParam((*param).into())),
|
||||||
PathResolution::SelfType(impl_def) => Some(TypeNs::SelfType((*impl_def).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::{
|
use crate::{
|
||||||
db::HirDatabase, semantics::PathResolution, Adt, BuiltinAttr, BuiltinType, Const, Field,
|
db::HirDatabase, semantics::PathResolution, Adt, AssocItem, BuiltinAttr, BuiltinType, Const,
|
||||||
Function, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias, Variant,
|
Field, Function, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias,
|
||||||
|
Variant,
|
||||||
};
|
};
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
|
|
||||||
|
@ -302,7 +303,7 @@ impl SourceAnalyzer {
|
||||||
let expr_id = self.expr_id(db, &path_expr.into())?;
|
let expr_id = self.expr_id(db, &path_expr.into())?;
|
||||||
let infer = self.infer.as_ref()?;
|
let infer = self.infer.as_ref()?;
|
||||||
if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
|
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)) =
|
if let Some(VariantId::EnumVariantId(variant)) =
|
||||||
infer.variant_resolution_for_expr(expr_id)
|
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) {
|
} else if let Some(path_pat) = parent().and_then(ast::PathPat::cast) {
|
||||||
let pat_id = self.pat_id(&path_pat.into())?;
|
let pat_id = self.pat_id(&path_pat.into())?;
|
||||||
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
|
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)) =
|
if let Some(VariantId::EnumVariantId(variant)) =
|
||||||
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
|
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::Macro(_))
|
||||||
| hir::PathResolution::Def(hir::ModuleDef::Module(_))
|
| hir::PathResolution::Def(hir::ModuleDef::Module(_))
|
||||||
| hir::PathResolution::Def(hir::ModuleDef::Static(_)) => return None,
|
| 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::BuiltinAttr(_)
|
||||||
| hir::PathResolution::ToolModule(_)
|
| hir::PathResolution::ToolModule(_)
|
||||||
| hir::PathResolution::Local(_)
|
| 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)? {
|
let function = match ctx.sema.resolve_path(&path)? {
|
||||||
PathResolution::Def(hir::ModuleDef::Function(f)) => f,
|
PathResolution::Def(hir::ModuleDef::Function(f)) => f,
|
||||||
PathResolution::AssocItem(hir::AssocItem::Function(f)) => f,
|
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
(function, format!("Inline `{}`", path))
|
(function, format!("Inline `{}`", path))
|
||||||
|
|
|
@ -482,14 +482,6 @@ impl From<PathResolution> for Definition {
|
||||||
fn from(path_resolution: PathResolution) -> Self {
|
fn from(path_resolution: PathResolution) -> Self {
|
||||||
match path_resolution {
|
match path_resolution {
|
||||||
PathResolution::Def(def) => def.into(),
|
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::Local(local) => Definition::Local(local),
|
||||||
PathResolution::TypeParam(par) => Definition::GenericParam(par.into()),
|
PathResolution::TypeParam(par) => Definition::GenericParam(par.into()),
|
||||||
PathResolution::ConstParam(par) => Definition::GenericParam(par.into()),
|
PathResolution::ConstParam(par) => Definition::GenericParam(par.into()),
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::helpers::mod_path_to_ast;
|
use crate::helpers::mod_path_to_ast;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{HirDisplay, SemanticsScope};
|
use hir::{AsAssocItem, HirDisplay, SemanticsScope};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
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 let hir::ModuleDef::Trait(_) = def {
|
||||||
if matches!(path.segment()?.kind()?, ast::PathSegmentKind::Type { .. }) {
|
if matches!(path.segment()?.kind()?, ast::PathSegmentKind::Type { .. }) {
|
||||||
// `speculative_resolve` resolves segments like `<T as
|
// `speculative_resolve` resolves segments like `<T as
|
||||||
|
@ -222,7 +222,7 @@ impl<'a> Ctx<'a> {
|
||||||
hir::PathResolution::Local(_)
|
hir::PathResolution::Local(_)
|
||||||
| hir::PathResolution::ConstParam(_)
|
| hir::PathResolution::ConstParam(_)
|
||||||
| hir::PathResolution::SelfType(_)
|
| hir::PathResolution::SelfType(_)
|
||||||
| hir::PathResolution::AssocItem(_)
|
| hir::PathResolution::Def(_)
|
||||||
| hir::PathResolution::BuiltinAttr(_)
|
| hir::PathResolution::BuiltinAttr(_)
|
||||||
| hir::PathResolution::ToolModule(_) => (),
|
| hir::PathResolution::ToolModule(_) => (),
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use crate::errors::error;
|
use crate::errors::error;
|
||||||
use crate::{parsing, SsrError};
|
use crate::{parsing, SsrError};
|
||||||
|
use hir::AsAssocItem;
|
||||||
use ide_db::base_db::FilePosition;
|
use ide_db::base_db::FilePosition;
|
||||||
use parsing::Placeholder;
|
use parsing::Placeholder;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
@ -82,10 +83,12 @@ impl Resolver<'_, '_> {
|
||||||
.filter_map(|(path_node, resolved)| {
|
.filter_map(|(path_node, resolved)| {
|
||||||
if let Some(grandparent) = path_node.parent().and_then(|parent| parent.parent()) {
|
if let Some(grandparent) = path_node.parent().and_then(|parent| parent.parent()) {
|
||||||
if let Some(call_expr) = ast::CallExpr::cast(grandparent.clone()) {
|
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
|
resolved.resolution
|
||||||
{
|
{
|
||||||
let qualifier_type = self.resolution_scope.qualifier_type(path_node);
|
if function.as_assoc_item(self.resolution_scope.scope.db).is_some() {
|
||||||
|
let qualifier_type =
|
||||||
|
self.resolution_scope.qualifier_type(path_node);
|
||||||
return Some((
|
return Some((
|
||||||
grandparent,
|
grandparent,
|
||||||
UfcsCallInfo { call_expr, function, qualifier_type },
|
UfcsCallInfo { call_expr, function, qualifier_type },
|
||||||
|
@ -93,6 +96,7 @@ impl Resolver<'_, '_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -162,7 +166,9 @@ impl Resolver<'_, '_> {
|
||||||
|
|
||||||
fn ok_to_use_path_resolution(&self, resolution: &hir::PathResolution) -> bool {
|
fn ok_to_use_path_resolution(&self, resolution: &hir::PathResolution) -> bool {
|
||||||
match resolution {
|
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 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
|
// 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()`.
|
// calls. e.g. `Foo::bar($s)` should match `x.bar()`.
|
||||||
|
@ -172,7 +178,9 @@ impl Resolver<'_, '_> {
|
||||||
false
|
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.
|
// Not a function. Could be a constant or an associated type.
|
||||||
cov_mark::hit!(replace_associated_trait_constant);
|
cov_mark::hit!(replace_associated_trait_constant);
|
||||||
false
|
false
|
||||||
|
@ -229,7 +237,7 @@ impl<'db> ResolutionScope<'db> {
|
||||||
|assoc_item| {
|
|assoc_item| {
|
||||||
let item_name = assoc_item.name(self.scope.db)?;
|
let item_name = assoc_item.name(self.scope.db)?;
|
||||||
if item_name.to_smol_str().as_str() == name.text() {
|
if item_name.to_smol_str().as_str() == name.text() {
|
||||||
Some(hir::PathResolution::AssocItem(assoc_item))
|
Some(hir::PathResolution::Def(assoc_item.into()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue