Skip to content

Commit f65daf2

Browse files
Revert source_analyzer changes
1 parent afc1d18 commit f65daf2

File tree

2 files changed

+6
-55
lines changed

2 files changed

+6
-55
lines changed

crates/ra_hir/src/code_model.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ impl AssocItem {
696696
AssocItem::TypeAlias(t) => t.module(db),
697697
}
698698
}
699-
700699
pub fn container(self, db: &impl DefDatabase) -> AssocItemContainer {
701700
let container = match self {
702701
AssocItem::Function(it) => it.id.lookup(db).container,

crates/ra_hir/src/source_analyzer.rs

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@ use hir_def::{
2020
use hir_expand::{
2121
hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind,
2222
};
23-
use hir_ty::{
24-
method_resolution::{iterate_method_candidates, LookupMode},
25-
Canonical, InEnvironment, InferenceResult, TraitEnvironment,
26-
};
23+
use hir_ty::{InEnvironment, InferenceResult, TraitEnvironment};
2724
use ra_syntax::{
2825
ast::{self, AstNode},
2926
AstPtr, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextUnit,
3027
};
3128
use rustc_hash::FxHashSet;
3229

3330
use crate::{
34-
db::HirDatabase, Adt, AssocItem, Const, DefWithBody, EnumVariant, Function, Local, MacroDef,
35-
ModuleDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam,
31+
db::HirDatabase, Adt, Const, DefWithBody, EnumVariant, Function, Local, MacroDef, Name, Path,
32+
ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam,
3633
};
3734

3835
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
@@ -292,11 +289,9 @@ impl SourceAnalyzer {
292289

293290
pub fn resolve_path(&self, db: &impl HirDatabase, path: &ast::Path) -> Option<PathResolution> {
294291
if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
295-
let path_resolution = self
296-
.resolve_as_full_path(path_expr.clone())
297-
.or_else(|| self.resolve_as_path_to_method(db, &path_expr));
298-
if path_resolution.is_some() {
299-
return path_resolution;
292+
let expr_id = self.expr_id(&path_expr.into())?;
293+
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) {
294+
return Some(PathResolution::AssocItem(assoc.into()));
300295
}
301296
}
302297
if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
@@ -310,49 +305,6 @@ impl SourceAnalyzer {
310305
self.resolve_hir_path(db, &hir_path)
311306
}
312307

313-
fn resolve_as_full_path(&self, path_expr: ast::PathExpr) -> Option<PathResolution> {
314-
let expr_id = self.expr_id(&path_expr.into())?;
315-
self.infer
316-
.as_ref()?
317-
.assoc_resolutions_for_expr(expr_id)
318-
.map(|assoc| PathResolution::AssocItem(assoc.into()))
319-
}
320-
321-
fn resolve_as_path_to_method(
322-
&self,
323-
db: &impl HirDatabase,
324-
path_expr: &ast::PathExpr,
325-
) -> Option<PathResolution> {
326-
let full_path = path_expr.path()?;
327-
let path_to_method = full_path.qualifier()?;
328-
let method_name = full_path.segment()?.syntax().to_string();
329-
match self.resolve_path(db, &path_to_method)? {
330-
PathResolution::Def(ModuleDef::Adt(adt)) => {
331-
let ty = adt.ty(db);
332-
iterate_method_candidates(
333-
&Canonical { value: ty.ty.value, num_vars: 0 },
334-
db,
335-
ty.ty.environment,
336-
self.resolver.krate()?,
337-
&self.resolver.traits_in_scope(db),
338-
None,
339-
LookupMode::Path,
340-
|_, assoc_item_id| {
341-
let assoc = assoc_item_id.into();
342-
if let AssocItem::Function(function) = assoc {
343-
if function.name(db).to_string() == method_name {
344-
return Some(assoc);
345-
}
346-
}
347-
None
348-
},
349-
)
350-
}
351-
_ => None,
352-
}
353-
.map(PathResolution::AssocItem)
354-
}
355-
356308
fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> {
357309
let name = name_ref.as_name();
358310
let source_map = self.body_source_map.as_ref()?;

0 commit comments

Comments
 (0)