mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Merge #11795
11795: fix: Correctly suggest auto importing traits from aliases r=Veykril a=unexge Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11506 Co-authored-by: unexge <unexge@gmail.com>
This commit is contained in:
commit
c2ea378920
@ -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]
|
||||
fn no_trait_type_fuzzy_completion() {
|
||||
check(
|
||||
|
@ -639,6 +639,17 @@ fn path_import_candidate(
|
||||
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,
|
||||
},
|
||||
None => ImportCandidate::Path(PathImportCandidate { qualifier: None, name }),
|
||||
|
Loading…
Reference in New Issue
Block a user