Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/ide-completion/src/render.rs | 27 | ||||
| -rw-r--r-- | crates/ide-db/src/imports/import_assets.rs | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index 433d49820d..d24ebab55d 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -888,6 +888,33 @@ mod tests { } #[test] + fn trait_imported_as_underscore_should_not_appear_auto_import_again() { + // make sure there has no `requires_import` + // see https://github.com/rust-lang/rust-analyzer/issues/19767 + check_relevance( + r#" +//- /dep.rs crate:dep +pub trait MyTrait { + fn my_method(&self); +} + +//- /main.rs crate:main deps:dep +use dep::MyTrait as _; +struct MyStruct; +impl dep::MyTrait for MyStruct { + fn my_method(&self) {} +} +fn main() { + MyStruct::my_method$0 +} +"#, + expect![[r#" + me my_method(…) fn(&self) [] + "#]], + ); + } + + #[test] fn set_struct_type_completion_info() { check_relevance( r#" diff --git a/crates/ide-db/src/imports/import_assets.rs b/crates/ide-db/src/imports/import_assets.rs index 4f05714a55..e0501b5e44 100644 --- a/crates/ide-db/src/imports/import_assets.rs +++ b/crates/ide-db/src/imports/import_assets.rs @@ -454,6 +454,7 @@ impl<'db> ImportAssets<'db> { |trait_to_import| { !scope_definitions .contains(&ScopeDef::ModuleDef(ModuleDef::Trait(trait_to_import))) + && !scope.can_use_trait_methods(trait_to_import) }, ), } |