File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed
crates/ide-completion/src Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -1679,12 +1679,16 @@ fn pattern_context_for(
16791679 let mut param_ctx = None ;
16801680
16811681 let mut missing_variants = vec ! [ ] ;
1682+ let is_pat_like = |kind| {
1683+ ast:: Pat :: can_cast ( kind)
1684+ || ast:: RecordPatField :: can_cast ( kind)
1685+ || ast:: RecordPatFieldList :: can_cast ( kind)
1686+ } ;
16821687
1683- let ( refutability, has_type_ascription) =
1684- pat
1688+ let ( refutability, has_type_ascription) = pat
16851689 . syntax ( )
16861690 . ancestors ( )
1687- . find ( |it| !ast :: Pat :: can_cast ( it. kind ( ) ) )
1691+ . find ( |it| !is_pat_like ( it. kind ( ) ) )
16881692 . map_or ( ( PatternRefutability :: Irrefutable , false ) , |node| {
16891693 let refutability = match_ast ! {
16901694 match node {
Original file line number Diff line number Diff line change @@ -132,6 +132,44 @@ fn foo() {
132132 ) ;
133133}
134134
135+ #[ test]
136+ fn refutable_in_record_pat_field ( ) {
137+ check (
138+ r#"
139+ enum Bar { Value, Nil }
140+ struct Foo { x: Bar }
141+ fn foo(foo: Foo) { match foo { Foo { x: $0 } } }
142+ "# ,
143+ expect ! [ [ r#"
144+ en Bar
145+ st Foo
146+ bn Foo {…} Foo { x$1 }$0
147+ kw mut
148+ kw ref
149+ "# ] ] ,
150+ ) ;
151+
152+ check (
153+ r#"
154+ enum Bar { Value, Nil }
155+ use Bar::*;
156+ struct Foo { x: Bar }
157+ fn foo(foo: Foo) { match foo { Foo { x: $0 } } }
158+ "# ,
159+ expect ! [ [ r#"
160+ en Bar
161+ st Foo
162+ ev Nil
163+ ev Value
164+ bn Foo {…} Foo { x$1 }$0
165+ bn Nil Nil$0
166+ bn Value Value$0
167+ kw mut
168+ kw ref
169+ "# ] ] ,
170+ ) ;
171+ }
172+
135173#[ test]
136174fn irrefutable ( ) {
137175 check_with_base_items (
You can’t perform that action at this time.
0 commit comments