From 81961dc035106dcfd29b894aae339261a0ba037b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 20 Mar 2021 11:04:01 +0200 Subject: Do not propose assoc items without qualifiers --- crates/hir_ty/src/autoderef.rs | 1 + crates/ide_completion/src/completions/flyimport.rs | 32 ++++++++++++++++++++++ crates/ide_db/src/helpers/import_assets.rs | 8 ++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs index 23ab042c1..0b8ac455b 100644 --- a/crates/hir_ty/src/autoderef.rs +++ b/crates/hir_ty/src/autoderef.rs @@ -27,6 +27,7 @@ pub fn autoderef<'a>( krate: Option, ty: InEnvironment>, ) -> impl Iterator> + 'a { + // from_chalk let InEnvironment { value: ty, environment } = ty; successors(Some(ty), move |ty| { deref(db, krate?, InEnvironment { value: ty, environment: environment.clone() }) diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 08df2df3f..f6c7d507f 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -943,6 +943,38 @@ mod foo { fn main() { bar::Ass$0 +}"#, + expect![[]], + ) + } + + #[test] + fn local_assoc_items_are_omitted() { + check( + r#" +mod something { + pub trait BaseTrait { + fn test_function() -> i32; + } + + pub struct Item1; + pub struct Item2; + + impl BaseTrait for Item1 { + fn test_function() -> i32 { + 1 + } + } + + impl BaseTrait for Item2 { + fn test_function() -> i32 { + 2 + } + } +} + +fn main() { + test_f$0 }"#, expect![[]], ) diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index 7c8844e95..dbc980ba9 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -304,10 +304,12 @@ fn path_applicable_imports( return items_with_candidate_name .into_iter() .filter_map(|item| { - let mut mod_path = mod_path(item)?; - if let Some(assoc_item) = item_as_assoc(db, item) { - mod_path.push_segment(assoc_item.name(db)?); + if item_as_assoc(db, item).is_some() { + // unqualified assoc items are not valid syntax + return None; } + + let mod_path = mod_path(item)?; Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path))) }) .collect(); -- cgit v1.2.3