diff options
| author | bors <bors@rust-lang.org> | 2022-07-28 15:51:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-28 15:51:30 +0000 |
| commit | 32e640e2ba390bb20479d744aa1d2ea380917615 (patch) | |
| tree | 1a2648d66a44c7e4678d6ac6b50705ff11a46897 | |
| parent | af2b806c1cdb27f3b3ea4afc32400b9e89415a89 (diff) | |
| parent | ce7541260d6a5c76633b4c0e2e1639730018773d (diff) | |
| download | rust-32e640e2ba390bb20479d744aa1d2ea380917615.tar.gz rust-32e640e2ba390bb20479d744aa1d2ea380917615.zip | |
Auto merge of #12901 - Veykril:completion-trait-expr, r=Veykril
fix: Don't complete marker traits in expression position cc https://github.com/rust-lang/rust-analyzer/issues/12196
| -rw-r--r-- | crates/ide-completion/src/completions/expr.rs | 17 | ||||
| -rw-r--r-- | crates/ide-completion/src/render.rs | 3 | ||||
| -rw-r--r-- | crates/ide-completion/src/tests/expression.rs | 2 | ||||
| -rw-r--r-- | crates/ide-completion/src/tests/record.rs | 1 |
4 files changed, 14 insertions, 9 deletions
diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs index bafaeb502ad..5d0ddaaf2a2 100644 --- a/crates/ide-completion/src/completions/expr.rs +++ b/crates/ide-completion/src/completions/expr.rs @@ -202,10 +202,21 @@ pub(crate) fn complete_expr_path( } } } - ctx.process_all_names(&mut |name, def| { - if scope_def_applicable(def) { - acc.add_path_resolution(ctx, path_ctx, name, def); + ctx.process_all_names(&mut |name, def| match def { + ScopeDef::ModuleDef(hir::ModuleDef::Trait(t)) => { + let assocs = t.items_with_supertraits(ctx.db); + match &*assocs { + // traits with no assoc items are unusable as expressions since + // there is no associated item path that can be constructed with them + [] => (), + // FIXME: Render the assoc item with the trait qualified + &[_item] => acc.add_path_resolution(ctx, path_ctx, name, def), + // FIXME: Append `::` to the thing here, since a trait on its own won't work + [..] => acc.add_path_resolution(ctx, path_ctx, name, def), + } } + _ if scope_def_applicable(def) => acc.add_path_resolution(ctx, path_ctx, name, def), + _ => (), }); if is_func_update.is_none() { diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index 9b25964a608..39cf9571379 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -1347,7 +1347,6 @@ fn main() { fn main() [] fn foo(…) [] md core [] - tt Sized [] "#]], ) } @@ -1394,7 +1393,6 @@ fn main() { fn main() [] fn foo(…) [] md core [] - tt Sized [] "#]], ) } @@ -1492,7 +1490,6 @@ fn main() { fn &bar() [type] fn foo(…) [] md core [] - tt Sized [] "#]], ) } diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index ce9d01d337b..ce7a543d9f3 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -44,7 +44,6 @@ fn baz() { st Record st Tuple st Unit - tt Trait un Union ev TupleV(…) TupleV(u32) bt u32 @@ -137,7 +136,6 @@ impl Unit { st Record st Tuple st Unit - tt Trait tp TypeParam un Union ev TupleV(…) TupleV(u32) diff --git a/crates/ide-completion/src/tests/record.rs b/crates/ide-completion/src/tests/record.rs index ec32602fa3c..f6accc68e5e 100644 --- a/crates/ide-completion/src/tests/record.rs +++ b/crates/ide-completion/src/tests/record.rs @@ -167,7 +167,6 @@ fn main() { st Foo st Foo {…} Foo { foo1: u32, foo2: u32 } tt Default - tt Sized bt u32 kw crate:: kw self:: |
