Skip to content

Commit 32e640e

Browse files
committed
Auto merge of rust-lang#12901 - Veykril:completion-trait-expr, r=Veykril
fix: Don't complete marker traits in expression position cc rust-lang/rust-analyzer#12196
2 parents af2b806 + ce75412 commit 32e640e

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,21 @@ pub(crate) fn complete_expr_path(
202202
}
203203
}
204204
}
205-
ctx.process_all_names(&mut |name, def| {
206-
if scope_def_applicable(def) {
207-
acc.add_path_resolution(ctx, path_ctx, name, def);
205+
ctx.process_all_names(&mut |name, def| match def {
206+
ScopeDef::ModuleDef(hir::ModuleDef::Trait(t)) => {
207+
let assocs = t.items_with_supertraits(ctx.db);
208+
match &*assocs {
209+
// traits with no assoc items are unusable as expressions since
210+
// there is no associated item path that can be constructed with them
211+
[] => (),
212+
// FIXME: Render the assoc item with the trait qualified
213+
&[_item] => acc.add_path_resolution(ctx, path_ctx, name, def),
214+
// FIXME: Append `::` to the thing here, since a trait on its own won't work
215+
[..] => acc.add_path_resolution(ctx, path_ctx, name, def),
216+
}
208217
}
218+
_ if scope_def_applicable(def) => acc.add_path_resolution(ctx, path_ctx, name, def),
219+
_ => (),
209220
});
210221

211222
if is_func_update.is_none() {

crates/ide-completion/src/render.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,6 @@ fn main() {
13471347
fn main() []
13481348
fn foo(…) []
13491349
md core []
1350-
tt Sized []
13511350
"#]],
13521351
)
13531352
}
@@ -1394,7 +1393,6 @@ fn main() {
13941393
fn main() []
13951394
fn foo(…) []
13961395
md core []
1397-
tt Sized []
13981396
"#]],
13991397
)
14001398
}
@@ -1492,7 +1490,6 @@ fn main() {
14921490
fn &bar() [type]
14931491
fn foo(…) []
14941492
md core []
1495-
tt Sized []
14961493
"#]],
14971494
)
14981495
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ fn baz() {
4444
st Record
4545
st Tuple
4646
st Unit
47-
tt Trait
4847
un Union
4948
ev TupleV(…) TupleV(u32)
5049
bt u32
@@ -137,7 +136,6 @@ impl Unit {
137136
st Record
138137
st Tuple
139138
st Unit
140-
tt Trait
141139
tp TypeParam
142140
un Union
143141
ev TupleV(…) TupleV(u32)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ fn main() {
167167
st Foo
168168
st Foo {…} Foo { foo1: u32, foo2: u32 }
169169
tt Default
170-
tt Sized
171170
bt u32
172171
kw crate::
173172
kw self::

0 commit comments

Comments
 (0)