Skip to content

Commit 8da5f46

Browse files
bors[bot]Veykril
andauthored
Merge #11158
11158: fix: Enable completions for `<_>::$0` r=Veykril a=Veykril Fixes #10462 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 55f3297 + 809461c commit 8da5f46

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

crates/ide_completion/src/completions/qualified_path.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::iter;
44

5-
use hir::ScopeDef;
5+
use hir::{ScopeDef, Trait};
66
use rustc_hash::FxHashSet;
77
use syntax::{ast, AstNode};
88

@@ -27,6 +27,25 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
2727
_ => return,
2828
};
2929

30+
// special case `<_>::$0` as this doesn't resolve to anything.
31+
if path.qualifier().is_none() {
32+
if matches!(
33+
path.segment().and_then(|it| it.kind()),
34+
Some(ast::PathSegmentKind::Type {
35+
type_ref: Some(ast::Type::InferType(_)),
36+
trait_ref: None,
37+
})
38+
) {
39+
cov_mark::hit!(completion_type_anchor_empty);
40+
ctx.scope
41+
.visible_traits()
42+
.into_iter()
43+
.flat_map(|it| Trait::from(it).items(ctx.sema.db))
44+
.for_each(|item| add_assoc_item(acc, ctx, item));
45+
return;
46+
}
47+
}
48+
3049
let resolution = match ctx.sema.resolve_path(path) {
3150
Some(res) => res,
3251
None => return,
@@ -707,4 +726,28 @@ pub mod m {}
707726
expect![[r#""#]],
708727
)
709728
}
729+
730+
#[test]
731+
fn type_anchor_empty() {
732+
cov_mark::check!(completion_type_anchor_empty);
733+
check(
734+
r#"
735+
trait Foo {
736+
fn foo() -> Self;
737+
}
738+
struct Bar;
739+
impl Foo for Bar {
740+
fn foo() -> {
741+
Bar
742+
}
743+
}
744+
fn bar() -> Bar {
745+
<_>::$0
746+
}
747+
"#,
748+
expect![[r#"
749+
fn foo() (as Foo) fn() -> Self
750+
"#]],
751+
)
752+
}
710753
}

0 commit comments

Comments
 (0)