Skip to content

Commit ce8e028

Browse files
bors[bot]Veykril
andauthored
Merge #11872
11872: internal: Remove `PathResolution::AssocItem` r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents ee84622 + c290e68 commit ce8e028

File tree

7 files changed

+28
-36
lines changed

7 files changed

+28
-36
lines changed

crates/hir/src/semantics.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use crate::{
3030
db::HirDatabase,
3131
semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
3232
source_analyzer::{resolve_hir_path, SourceAnalyzer},
33-
Access, AssocItem, BuiltinAttr, Callable, ConstParam, Crate, Field, Function, HasSource,
34-
HirFileId, Impl, InFile, Label, LifetimeParam, Local, Macro, Module, ModuleDef, Name, Path,
35-
ScopeDef, ToolModule, Trait, Type, TypeAlias, TypeParam, VariantDef,
33+
Access, BuiltinAttr, Callable, ConstParam, Crate, Field, Function, HasSource, HirFileId, Impl,
34+
InFile, Label, LifetimeParam, Local, Macro, Module, ModuleDef, Name, Path, ScopeDef,
35+
ToolModule, Trait, Type, TypeAlias, TypeParam, VariantDef,
3636
};
3737

3838
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -46,7 +46,6 @@ pub enum PathResolution {
4646
/// A const parameter
4747
ConstParam(ConstParam),
4848
SelfType(Impl),
49-
AssocItem(AssocItem),
5049
BuiltinAttr(BuiltinAttr),
5150
ToolModule(ToolModule),
5251
}
@@ -76,10 +75,6 @@ impl PathResolution {
7675
| PathResolution::ConstParam(_) => None,
7776
PathResolution::TypeParam(param) => Some(TypeNs::GenericParam((*param).into())),
7877
PathResolution::SelfType(impl_def) => Some(TypeNs::SelfType((*impl_def).into())),
79-
PathResolution::AssocItem(AssocItem::Const(_) | AssocItem::Function(_)) => None,
80-
PathResolution::AssocItem(AssocItem::TypeAlias(alias)) => {
81-
Some(TypeNs::TypeAliasId((*alias).into()))
82-
}
8378
}
8479
}
8580
}

crates/hir/src/source_analyzer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ use syntax::{
4040
};
4141

4242
use crate::{
43-
db::HirDatabase, semantics::PathResolution, Adt, BuiltinAttr, BuiltinType, Const, Field,
44-
Function, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias, Variant,
43+
db::HirDatabase, semantics::PathResolution, Adt, AssocItem, BuiltinAttr, BuiltinType, Const,
44+
Field, Function, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias,
45+
Variant,
4546
};
4647
use base_db::CrateId;
4748

@@ -302,7 +303,7 @@ impl SourceAnalyzer {
302303
let expr_id = self.expr_id(db, &path_expr.into())?;
303304
let infer = self.infer.as_ref()?;
304305
if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
305-
return Some(PathResolution::AssocItem(assoc.into()));
306+
return Some(PathResolution::Def(AssocItem::from(assoc).into()));
306307
}
307308
if let Some(VariantId::EnumVariantId(variant)) =
308309
infer.variant_resolution_for_expr(expr_id)
@@ -313,7 +314,7 @@ impl SourceAnalyzer {
313314
} else if let Some(path_pat) = parent().and_then(ast::PathPat::cast) {
314315
let pat_id = self.pat_id(&path_pat.into())?;
315316
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
316-
return Some(PathResolution::AssocItem(assoc.into()));
317+
return Some(PathResolution::Def(AssocItem::from(assoc).into()));
317318
}
318319
if let Some(VariantId::EnumVariantId(variant)) =
319320
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)

crates/ide/src/signature_help.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,6 @@ fn signature_help_for_generics(
198198
| hir::PathResolution::Def(hir::ModuleDef::Macro(_))
199199
| hir::PathResolution::Def(hir::ModuleDef::Module(_))
200200
| hir::PathResolution::Def(hir::ModuleDef::Static(_)) => return None,
201-
hir::PathResolution::AssocItem(hir::AssocItem::Function(it)) => it.into(),
202-
hir::PathResolution::AssocItem(hir::AssocItem::TypeAlias(it)) => it.into(),
203-
hir::PathResolution::AssocItem(hir::AssocItem::Const(_)) => return None,
204201
hir::PathResolution::BuiltinAttr(_)
205202
| hir::PathResolution::ToolModule(_)
206203
| hir::PathResolution::Local(_)

crates/ide_assists/src/handlers/inline_call.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
185185
}?;
186186
let function = match ctx.sema.resolve_path(&path)? {
187187
PathResolution::Def(hir::ModuleDef::Function(f)) => f,
188-
PathResolution::AssocItem(hir::AssocItem::Function(f)) => f,
189188
_ => return None,
190189
};
191190
(function, format!("Inline `{}`", path))

crates/ide_db/src/defs.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,6 @@ impl From<PathResolution> for Definition {
482482
fn from(path_resolution: PathResolution) -> Self {
483483
match path_resolution {
484484
PathResolution::Def(def) => def.into(),
485-
PathResolution::AssocItem(item) => {
486-
let def: ModuleDef = match item {
487-
hir::AssocItem::Function(it) => it.into(),
488-
hir::AssocItem::Const(it) => it.into(),
489-
hir::AssocItem::TypeAlias(it) => it.into(),
490-
};
491-
def.into()
492-
}
493485
PathResolution::Local(local) => Definition::Local(local),
494486
PathResolution::TypeParam(par) => Definition::GenericParam(par.into()),
495487
PathResolution::ConstParam(par) => Definition::GenericParam(par.into()),

crates/ide_db/src/path_transform.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::helpers::mod_path_to_ast;
44
use either::Either;
5-
use hir::{HirDisplay, SemanticsScope};
5+
use hir::{AsAssocItem, HirDisplay, SemanticsScope};
66
use rustc_hash::FxHashMap;
77
use syntax::{
88
ast::{self, AstNode},
@@ -197,7 +197,7 @@ impl<'a> Ctx<'a> {
197197
}
198198
}
199199
}
200-
hir::PathResolution::Def(def) => {
200+
hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => {
201201
if let hir::ModuleDef::Trait(_) = def {
202202
if matches!(path.segment()?.kind()?, ast::PathSegmentKind::Type { .. }) {
203203
// `speculative_resolve` resolves segments like `<T as
@@ -222,7 +222,7 @@ impl<'a> Ctx<'a> {
222222
hir::PathResolution::Local(_)
223223
| hir::PathResolution::ConstParam(_)
224224
| hir::PathResolution::SelfType(_)
225-
| hir::PathResolution::AssocItem(_)
225+
| hir::PathResolution::Def(_)
226226
| hir::PathResolution::BuiltinAttr(_)
227227
| hir::PathResolution::ToolModule(_) => (),
228228
}

crates/ide_ssr/src/resolving.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::errors::error;
44
use crate::{parsing, SsrError};
5+
use hir::AsAssocItem;
56
use ide_db::base_db::FilePosition;
67
use parsing::Placeholder;
78
use rustc_hash::FxHashMap;
@@ -82,14 +83,17 @@ impl Resolver<'_, '_> {
8283
.filter_map(|(path_node, resolved)| {
8384
if let Some(grandparent) = path_node.parent().and_then(|parent| parent.parent()) {
8485
if let Some(call_expr) = ast::CallExpr::cast(grandparent.clone()) {
85-
if let hir::PathResolution::AssocItem(hir::AssocItem::Function(function)) =
86+
if let hir::PathResolution::Def(hir::ModuleDef::Function(function)) =
8687
resolved.resolution
8788
{
88-
let qualifier_type = self.resolution_scope.qualifier_type(path_node);
89-
return Some((
90-
grandparent,
91-
UfcsCallInfo { call_expr, function, qualifier_type },
92-
));
89+
if function.as_assoc_item(self.resolution_scope.scope.db).is_some() {
90+
let qualifier_type =
91+
self.resolution_scope.qualifier_type(path_node);
92+
return Some((
93+
grandparent,
94+
UfcsCallInfo { call_expr, function, qualifier_type },
95+
));
96+
}
9397
}
9498
}
9599
}
@@ -162,7 +166,9 @@ impl Resolver<'_, '_> {
162166

163167
fn ok_to_use_path_resolution(&self, resolution: &hir::PathResolution) -> bool {
164168
match resolution {
165-
hir::PathResolution::AssocItem(hir::AssocItem::Function(function)) => {
169+
hir::PathResolution::Def(hir::ModuleDef::Function(function))
170+
if function.as_assoc_item(self.resolution_scope.scope.db).is_some() =>
171+
{
166172
if function.self_param(self.resolution_scope.scope.db).is_some() {
167173
// If we don't use this path resolution, then we won't be able to match method
168174
// calls. e.g. `Foo::bar($s)` should match `x.bar()`.
@@ -172,7 +178,9 @@ impl Resolver<'_, '_> {
172178
false
173179
}
174180
}
175-
hir::PathResolution::AssocItem(_) => {
181+
hir::PathResolution::Def(
182+
def @ (hir::ModuleDef::Const(_) | hir::ModuleDef::TypeAlias(_)),
183+
) if def.as_assoc_item(self.resolution_scope.scope.db).is_some() => {
176184
// Not a function. Could be a constant or an associated type.
177185
cov_mark::hit!(replace_associated_trait_constant);
178186
false
@@ -229,7 +237,7 @@ impl<'db> ResolutionScope<'db> {
229237
|assoc_item| {
230238
let item_name = assoc_item.name(self.scope.db)?;
231239
if item_name.to_smol_str().as_str() == name.text() {
232-
Some(hir::PathResolution::AssocItem(assoc_item))
240+
Some(hir::PathResolution::Def(assoc_item.into()))
233241
} else {
234242
None
235243
}

0 commit comments

Comments
 (0)