Skip to content

Commit a566f02

Browse files
committed
reformat code
1 parent 96e9652 commit a566f02

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

crates/hir-ty/src/method_resolution.rs

+26-21
Original file line numberDiff line numberDiff line change
@@ -997,33 +997,38 @@ pub fn resolve_indexing_op(
997997
struct Valid;
998998
impl Valid {
999999
fn valid_impl(
1000-
impls: impl Iterator<Item = ImplId>,
1000+
mut impls: impl Iterator<Item = ImplId>,
10011001
table: &mut InferenceTable,
10021002
self_ty: &Ty,
10031003
) -> Option<Arc<ImplData>> {
10041004
let db = table.db;
1005-
for impl_ in impls {
1006-
let impl_data = db.impl_data(impl_);
1007-
let substs =
1008-
TyBuilder::subst_for_def(db, impl_).fill_with_inference_vars(table).build();
1009-
let impl_ty =
1010-
substs.apply(db.impl_self_ty(impl_).into_value_and_skipped_binders().0, Interner);
1011-
1012-
if !table.unify(self_ty, &impl_ty) {
1013-
continue;
1014-
}
1015-
1016-
let wh_goals = crate::chalk_db::convert_where_clauses(db, impl_.into(), &substs)
1017-
.into_iter()
1018-
.map(|b| b.into_well_formed_goal(Interner).cast(Interner));
1019-
1020-
let goal = crate::Goal::all(Interner, wh_goals);
1021-
1022-
if table.try_obligation(goal).is_some() {
1023-
return Some(impl_data);
1005+
loop {
1006+
let impl_ = impls.next()?;
1007+
let r = table.run_in_snapshot(|table| {
1008+
let impl_data = db.impl_data(impl_);
1009+
let substs =
1010+
TyBuilder::subst_for_def(db, impl_).fill_with_inference_vars(table).build();
1011+
let impl_ty = substs
1012+
.apply(db.impl_self_ty(impl_).into_value_and_skipped_binders().0, Interner);
1013+
1014+
table
1015+
.unify(self_ty, &impl_ty)
1016+
.then(|| {
1017+
let wh_goals =
1018+
crate::chalk_db::convert_where_clauses(db, impl_.into(), &substs)
1019+
.into_iter()
1020+
.map(|b| b.into_well_formed_goal(Interner).cast(Interner));
1021+
1022+
let goal = crate::Goal::all(Interner, wh_goals);
1023+
1024+
table.try_obligation(goal).map(|_| impl_data)
1025+
})
1026+
.flatten()
1027+
});
1028+
if r.is_some() {
1029+
break r;
10241030
}
10251031
}
1026-
None
10271032
}
10281033

10291034
fn is_valid_item(

crates/ide-db/src/defs.rs

+17-23
Original file line numberDiff line numberDiff line change
@@ -438,29 +438,23 @@ impl NameRefClass {
438438
name_ref: ast::NameRef,
439439
) -> Option<NameRefClass> {
440440
let parent = name_ref.syntax().parent()?;
441-
match_ast! {
442-
match parent {
443-
ast::MethodCallExpr(method_call) => {
444-
sema.resolve_impl_method(&ast::Expr::MethodCallExpr(method_call))
445-
.map(Definition::Function)
446-
.map(NameRefClass::Definition)
447-
},
448-
ast::PathSegment(ps) => {
449-
ps.syntax().parent().and_then(ast::Path::cast)
450-
.map(|p|
451-
p.syntax()
452-
.parent()
453-
.and_then(ast::PathExpr::cast)
454-
.map(|pe|
455-
sema.resolve_impl_method(&ast::Expr::PathExpr(pe))
456-
.map(Definition::Function)
457-
.map(NameRefClass::Definition)
458-
).flatten()
459-
).flatten()
460-
},
461-
_=> None
462-
}
463-
}
441+
let expr = match_ast! {
442+
match parent {
443+
ast::MethodCallExpr(method_call) => {
444+
Some(ast::Expr::MethodCallExpr(method_call))
445+
},
446+
ast::PathSegment(..) => {
447+
parent.ancestors()
448+
.find_map(ast::PathExpr::cast)
449+
.map(ast::Expr::PathExpr)
450+
},
451+
_=> None
452+
}
453+
};
454+
expr.as_ref()
455+
.and_then(|e| sema.resolve_impl_method(e))
456+
.map(Definition::Function)
457+
.map(NameRefClass::Definition)
464458
}
465459
pub fn classify_lifetime(
466460
sema: &Semantics<RootDatabase>,

0 commit comments

Comments
 (0)