File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -297,6 +297,47 @@ fn main() {
297297 ) ;
298298}
299299
300+ #[ test]
301+ fn trait_method_from_alias ( ) {
302+ let fixture = r#"
303+ //- /lib.rs crate:dep
304+ pub mod test_mod {
305+ pub trait TestTrait {
306+ fn random_method();
307+ }
308+ pub struct TestStruct {}
309+ impl TestTrait for TestStruct {
310+ fn random_method() {}
311+ }
312+ pub type TestAlias = TestStruct;
313+ }
314+
315+ //- /main.rs crate:main deps:dep
316+ fn main() {
317+ dep::test_mod::TestAlias::ran$0
318+ }
319+ "# ;
320+
321+ check (
322+ fixture,
323+ expect ! [ [ r#"
324+ fn random_method() (use dep::test_mod::TestTrait) fn()
325+ "# ] ] ,
326+ ) ;
327+
328+ check_edit (
329+ "random_method" ,
330+ fixture,
331+ r#"
332+ use dep::test_mod::TestTrait;
333+
334+ fn main() {
335+ dep::test_mod::TestAlias::random_method()$0
336+ }
337+ "# ,
338+ ) ;
339+ }
340+
300341#[ test]
301342fn no_trait_type_fuzzy_completion ( ) {
302343 check (
Original file line number Diff line number Diff line change @@ -639,6 +639,17 @@ fn path_import_candidate(
639639 assoc_item_name : name,
640640 } )
641641 }
642+ Some ( PathResolution :: Def ( ModuleDef :: TypeAlias ( alias) ) ) => {
643+ let ty = alias. ty ( sema. db ) ;
644+ if ty. as_adt ( ) . is_some ( ) {
645+ ImportCandidate :: TraitAssocItem ( TraitImportCandidate {
646+ receiver_ty : ty,
647+ assoc_item_name : name,
648+ } )
649+ } else {
650+ return None ;
651+ }
652+ }
642653 Some ( _) => return None ,
643654 } ,
644655 None => ImportCandidate :: Path ( PathImportCandidate { qualifier : None , name } ) ,
You can’t perform that action at this time.
0 commit comments