diff options
| author | A4-Tacks <wdsjxhno1001@163.com> | 2025-09-17 14:59:02 +0800 |
|---|---|---|
| committer | A4-Tacks <wdsjxhno1001@163.com> | 2025-09-17 15:11:22 +0800 |
| commit | 603d64c3bb61e5e39bf624cc152fe1b844e70220 (patch) | |
| tree | d6722d131aef11a7c2e3f63292041e625f5325a3 | |
| parent | c307fd8e3320bbaabd68a5299e6fb89ad703887b (diff) | |
| download | rust-603d64c3bb61e5e39bf624cc152fe1b844e70220.tar.gz rust-603d64c3bb61e5e39bf624cc152fe1b844e70220.zip | |
Fix complete type in nested pattern
Example
---
```rust
struct Foo { num: u32 }
struct Bar(Foo);
fn foo(Bar($0)) {}
```
**Before this PR**:
```rust
struct Foo { num: u32 }
struct Bar(Foo);
fn foo(Bar(Foo { num$1 }: Foo$0)) {}
```
**After this PR**:
```rust
struct Foo { num: u32 }
struct Bar(Foo);
fn foo(Bar(Foo { num$1 }$0)) {}
```
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-completion/src/render/pattern.rs | 1 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/render/pattern.rs b/src/tools/rust-analyzer/crates/ide-completion/src/render/pattern.rs index 60ec1128233..312d3bd426f 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/render/pattern.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/render/pattern.rs @@ -163,6 +163,7 @@ fn render_pat( PatternContext { param_ctx: Some(ParamContext { kind: ParamKind::Function(_), .. }), has_type_ascription: false, + parent_pat: None, .. } ); diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs b/src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs index 9ec27252fd7..6eb0b818d69 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs @@ -399,6 +399,25 @@ fn foo($0) {} } #[test] +fn completes_in_fn_param_in_nested_pattern() { + check( + r#" +struct Foo { num: u32 } +struct Bar(Foo); +fn foo(Bar($0)) {} +"#, + expect![[r#" + st Bar + st Foo + bn Bar(…) Bar($1)$0 + bn Foo {…} Foo { num$1 }$0 + kw mut + kw ref + "#]], + ) +} + +#[test] fn completes_in_closure_param() { check( r#" |
