diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs index fff193ba4c9b..017f920fccab 100644 --- a/crates/ide-completion/src/tests/flyimport.rs +++ b/crates/ide-completion/src/tests/flyimport.rs @@ -374,6 +374,129 @@ fn main() { ); } +#[test] +fn trait_method_fuzzy_completion_aware_of_fundamental_boxes() { + let fixture = r#" +//- /fundamental.rs crate:fundamental +#[lang = "owned_box"] +#[fundamental] +pub struct Box(T); +//- /foo.rs crate:foo +pub trait TestTrait { + fn some_method(&self); +} +//- /main.rs crate:main deps:foo,fundamental +struct TestStruct; + +impl foo::TestTrait for fundamental::Box { + fn some_method(&self) {} +} + +fn main() { + let t = fundamental::Box(TestStruct); + t.$0 +} +"#; + + check( + fixture, + expect![[r#" + me some_method() (use foo::TestTrait) fn(&self) + "#]], + ); + + check_edit( + "some_method", + fixture, + r#" +use foo::TestTrait; + +struct TestStruct; + +impl foo::TestTrait for fundamental::Box { + fn some_method(&self) {} +} + +fn main() { + let t = fundamental::Box(TestStruct); + t.some_method()$0 +} +"#, + ); +} + +#[test] +fn trait_method_fuzzy_completion_aware_of_fundamental_references() { + let fixture = r#" +//- /foo.rs crate:foo +pub trait TestTrait { + fn some_method(&self); +} +//- /main.rs crate:main deps:foo +struct TestStruct; + +impl foo::TestTrait for &TestStruct { + fn some_method(&self) {} +} + +fn main() { + let t = &TestStruct; + t.$0 +} +"#; + + check( + fixture, + expect![[r#" + me some_method() (use foo::TestTrait) fn(&self) + "#]], + ); + + check_edit( + "some_method", + fixture, + r#" +use foo::TestTrait; + +struct TestStruct; + +impl foo::TestTrait for &TestStruct { + fn some_method(&self) {} +} + +fn main() { + let t = &TestStruct; + t.some_method()$0 +} +"#, + ); +} + +#[test] +fn trait_method_fuzzy_completion_aware_of_unit_type() { + let fixture = r#" +//- minicore: from, sized +//- /main.rs crate:main +struct A; + +impl Into for () { + fn into(self) -> A { + A + } +} + +fn main() { + let a = A; + a.$0 +} +"#; + + // note that this test passing is incorrect, as we'd expect that traits like + // `Into` to show up in the completions. for whatever reason, they still show + // up in in a rust-analyzer actually performing completions. + check(fixture, expect![[r#""#]]); +} + #[test] fn trait_method_from_alias() { let fixture = r#"