mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Refactor a bit
This commit is contained in:
parent
f4181deb0d
commit
b0bf1deb7c
1 changed files with 25 additions and 36 deletions
|
@ -269,25 +269,9 @@ fn iterate_trait_method_candidates<T>(
|
||||||
// iteration
|
// iteration
|
||||||
let mut known_implemented = inherently_implemented;
|
let mut known_implemented = inherently_implemented;
|
||||||
for &item in data.items() {
|
for &item in data.items() {
|
||||||
// TODO unify with the impl case
|
if !is_valid_candidate(db, name, mode, item) {
|
||||||
match item {
|
continue;
|
||||||
AssocItem::Function(m) => {
|
}
|
||||||
let data = m.data(db);
|
|
||||||
if !name.map_or(true, |name| data.name() == name)
|
|
||||||
|| (!data.has_self_param() && mode != LookupMode::Path)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AssocItem::Const(c) => {
|
|
||||||
if !name.map_or(true, |name| Some(name) == c.name(db).as_ref())
|
|
||||||
|| (mode != LookupMode::Path)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
if !known_implemented {
|
if !known_implemented {
|
||||||
let goal = generic_implements_goal(db, env.clone(), t, ty.clone());
|
let goal = generic_implements_goal(db, env.clone(), t, ty.clone());
|
||||||
if db.trait_solve(krate, goal).is_none() {
|
if db.trait_solve(krate, goal).is_none() {
|
||||||
|
@ -316,23 +300,8 @@ fn iterate_inherent_methods<T>(
|
||||||
|
|
||||||
for impl_block in impls.lookup_impl_blocks(&ty.value) {
|
for impl_block in impls.lookup_impl_blocks(&ty.value) {
|
||||||
for item in impl_block.items(db) {
|
for item in impl_block.items(db) {
|
||||||
match item {
|
if !is_valid_candidate(db, name, mode, item) {
|
||||||
AssocItem::Function(f) => {
|
continue;
|
||||||
let data = f.data(db);
|
|
||||||
if !name.map_or(true, |name| data.name() == name)
|
|
||||||
|| (!data.has_self_param() && mode != LookupMode::Path)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AssocItem::Const(c) => {
|
|
||||||
if !name.map_or(true, |name| Some(name) == c.name(db).as_ref())
|
|
||||||
|| (mode != LookupMode::Path)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
if let Some(result) = callback(&ty.value, item) {
|
if let Some(result) = callback(&ty.value, item) {
|
||||||
return Some(result);
|
return Some(result);
|
||||||
|
@ -343,6 +312,26 @@ fn iterate_inherent_methods<T>(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_valid_candidate(
|
||||||
|
db: &impl HirDatabase,
|
||||||
|
name: Option<&Name>,
|
||||||
|
mode: LookupMode,
|
||||||
|
item: AssocItem,
|
||||||
|
) -> bool {
|
||||||
|
match item {
|
||||||
|
AssocItem::Function(m) => {
|
||||||
|
let data = m.data(db);
|
||||||
|
name.map_or(true, |name| data.name() == name)
|
||||||
|
&& (data.has_self_param() || mode == LookupMode::Path)
|
||||||
|
}
|
||||||
|
AssocItem::Const(c) => {
|
||||||
|
name.map_or(true, |name| Some(name) == c.name(db).as_ref())
|
||||||
|
&& (mode == LookupMode::Path)
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn implements_trait(
|
pub(crate) fn implements_trait(
|
||||||
ty: &Canonical<Ty>,
|
ty: &Canonical<Ty>,
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
|
|
Loading…
Reference in a new issue