Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0e47bef

Browse files
committed
fix flyimport showing other types in impl trait statement
1 parent 9897662 commit 0e47bef

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

crates/ide-completion/src/completions/flyimport.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ fn import_on_the_fly(
238238
(PathKind::Type { location }, ItemInNs::Types(ty)) => {
239239
if matches!(location, TypeLocation::TypeBound) {
240240
matches!(ty, ModuleDef::Trait(_))
241+
} else if matches!(location, TypeLocation::ImplTrait) {
242+
matches!(ty, ModuleDef::Trait(_)) || matches!(ty, ModuleDef::Module(_))
241243
} else {
242244
true
243245
}

crates/ide-completion/src/tests/flyimport.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,3 +1397,22 @@ pub use bridge2::server2::Span2;
13971397
"#]],
13981398
);
13991399
}
1400+
1401+
#[test]
1402+
fn flyimport_only_traits_in_impl_trait_block() {
1403+
check(
1404+
r#"
1405+
//- /main.rs crate:main deps:dep
1406+
pub struct Bar;
1407+
1408+
impl Foo$0 for Bar { }
1409+
//- /lib.rs crate:dep
1410+
pub trait FooTrait;
1411+
1412+
pub struct FooStruct;
1413+
"#,
1414+
expect![[r#"
1415+
tt FooTrait (use dep::FooTrait)
1416+
"#]],
1417+
);
1418+
}

0 commit comments

Comments
 (0)