fix: Correctly suggest auto importing traits from aliases
This commit is contained in:
parent
f1dbc2acd4
commit
4e4c9ea4ac
@ -297,6 +297,47 @@ fn main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trait_method_from_alias() {
|
||||||
|
let fixture = r#"
|
||||||
|
//- /lib.rs crate:dep
|
||||||
|
pub mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
fn random_method();
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
fn random_method() {}
|
||||||
|
}
|
||||||
|
pub type TestAlias = TestStruct;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- /main.rs crate:main deps:dep
|
||||||
|
fn main() {
|
||||||
|
dep::test_mod::TestAlias::ran$0
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
check(
|
||||||
|
fixture,
|
||||||
|
expect![[r#"
|
||||||
|
fn random_method() (use dep::test_mod::TestTrait) fn()
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
|
||||||
|
check_edit(
|
||||||
|
"random_method",
|
||||||
|
fixture,
|
||||||
|
r#"
|
||||||
|
use dep::test_mod::TestTrait;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
dep::test_mod::TestAlias::random_method()$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_trait_type_fuzzy_completion() {
|
fn no_trait_type_fuzzy_completion() {
|
||||||
check(
|
check(
|
||||||
|
@ -639,6 +639,17 @@ fn path_import_candidate(
|
|||||||
assoc_item_name: name,
|
assoc_item_name: name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Some(PathResolution::Def(ModuleDef::TypeAlias(alias))) => {
|
||||||
|
let ty = alias.ty(sema.db);
|
||||||
|
if ty.as_adt().is_some() {
|
||||||
|
ImportCandidate::TraitAssocItem(TraitImportCandidate {
|
||||||
|
receiver_ty: ty,
|
||||||
|
assoc_item_name: name,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some(_) => return None,
|
Some(_) => return None,
|
||||||
},
|
},
|
||||||
None => ImportCandidate::Path(PathImportCandidate { qualifier: None, name }),
|
None => ImportCandidate::Path(PathImportCandidate { qualifier: None, name }),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user