diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs index d6d3978385d9..e4076fc55588 100644 --- a/crates/ide-completion/src/context/analysis.rs +++ b/crates/ide-completion/src/context/analysis.rs @@ -1679,12 +1679,16 @@ fn pattern_context_for( let mut param_ctx = None; let mut missing_variants = vec![]; + let is_pat_like = |kind| { + ast::Pat::can_cast(kind) + || ast::RecordPatField::can_cast(kind) + || ast::RecordPatFieldList::can_cast(kind) + }; - let (refutability, has_type_ascription) = - pat + let (refutability, has_type_ascription) = pat .syntax() .ancestors() - .find(|it| !ast::Pat::can_cast(it.kind())) + .find(|it| !is_pat_like(it.kind())) .map_or((PatternRefutability::Irrefutable, false), |node| { let refutability = match_ast! { match node { diff --git a/crates/ide-completion/src/tests/pattern.rs b/crates/ide-completion/src/tests/pattern.rs index df0c4e540cd9..a765fd1278dd 100644 --- a/crates/ide-completion/src/tests/pattern.rs +++ b/crates/ide-completion/src/tests/pattern.rs @@ -132,6 +132,44 @@ fn foo() { ); } +#[test] +fn refutable_in_record_pat_field() { + check( + r#" +enum Bar { Value, Nil } +struct Foo { x: Bar } +fn foo(foo: Foo) { match foo { Foo { x: $0 } } } +"#, + expect![[r#" + en Bar + st Foo + bn Foo {…} Foo { x$1 }$0 + kw mut + kw ref + "#]], + ); + + check( + r#" +enum Bar { Value, Nil } +use Bar::*; +struct Foo { x: Bar } +fn foo(foo: Foo) { match foo { Foo { x: $0 } } } +"#, + expect![[r#" + en Bar + st Foo + ev Nil + ev Value + bn Foo {…} Foo { x$1 }$0 + bn Nil Nil$0 + bn Value Value$0 + kw mut + kw ref + "#]], + ); +} + #[test] fn irrefutable() { check_with_base_items(