Skip to content

Commit 81961dc

Browse files
Do not propose assoc items without qualifiers
1 parent 104a198 commit 81961dc

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

crates/hir_ty/src/autoderef.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub fn autoderef<'a>(
2727
krate: Option<CrateId>,
2828
ty: InEnvironment<Canonical<Ty>>,
2929
) -> impl Iterator<Item = Canonical<Ty>> + 'a {
30+
// from_chalk
3031
let InEnvironment { value: ty, environment } = ty;
3132
successors(Some(ty), move |ty| {
3233
deref(db, krate?, InEnvironment { value: ty, environment: environment.clone() })

crates/ide_completion/src/completions/flyimport.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,38 @@ mod foo {
943943
944944
fn main() {
945945
bar::Ass$0
946+
}"#,
947+
expect![[]],
948+
)
949+
}
950+
951+
#[test]
952+
fn local_assoc_items_are_omitted() {
953+
check(
954+
r#"
955+
mod something {
956+
pub trait BaseTrait {
957+
fn test_function() -> i32;
958+
}
959+
960+
pub struct Item1;
961+
pub struct Item2;
962+
963+
impl BaseTrait for Item1 {
964+
fn test_function() -> i32 {
965+
1
966+
}
967+
}
968+
969+
impl BaseTrait for Item2 {
970+
fn test_function() -> i32 {
971+
2
972+
}
973+
}
974+
}
975+
976+
fn main() {
977+
test_f$0
946978
}"#,
947979
expect![[]],
948980
)

crates/ide_db/src/helpers/import_assets.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,12 @@ fn path_applicable_imports(
304304
return items_with_candidate_name
305305
.into_iter()
306306
.filter_map(|item| {
307-
let mut mod_path = mod_path(item)?;
308-
if let Some(assoc_item) = item_as_assoc(db, item) {
309-
mod_path.push_segment(assoc_item.name(db)?);
307+
if item_as_assoc(db, item).is_some() {
308+
// unqualified assoc items are not valid syntax
309+
return None;
310310
}
311+
312+
let mod_path = mod_path(item)?;
311313
Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
312314
})
313315
.collect();

0 commit comments

Comments
 (0)