Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21065 from A4-Tacks/refutable-in-pat-field
Fix always irrefutable in RecordPatField
Lukas Wirth 5 months ago
parent 75b1e9b · parent 26f8499 · commit d597ef1
-rw-r--r--crates/ide-completion/src/context/analysis.rs10
-rw-r--r--crates/ide-completion/src/tests/pattern.rs38
2 files changed, 45 insertions, 3 deletions
diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs
index d6d3978385..e4076fc555 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 df0c4e540c..a765fd1278 100644
--- a/crates/ide-completion/src/tests/pattern.rs
+++ b/crates/ide-completion/src/tests/pattern.rs
@@ -133,6 +133,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(
r#"