Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crates/ide-completion/src/context/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions crates/ide-completion/src/tests/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down