diff options
author | Lukas Wirth <[email protected]> | 2020-12-20 19:13:06 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-12-20 19:13:06 +0000 |
commit | 33ecad4407e1345cd662f535c2ae7a04e4bee52b (patch) | |
tree | edd613981e78ac6b9f4ea23b511cb2922d79c67f /crates/completion/src/render | |
parent | a5874a38cb1bbaee685ff92a40b66f9d5bcf34f6 (diff) |
Create non-exhaustive patterns for non_exhaustive attributed items
Diffstat (limited to 'crates/completion/src/render')
-rw-r--r-- | crates/completion/src/render/pattern.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/crates/completion/src/render/pattern.rs b/crates/completion/src/render/pattern.rs index cfe2116bd..2d1600105 100644 --- a/crates/completion/src/render/pattern.rs +++ b/crates/completion/src/render/pattern.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! Renderer for patterns. | 1 | //! Renderer for patterns. |
2 | 2 | ||
3 | use hir::{db::HirDatabase, HasVisibility, Name, StructKind}; | 3 | use hir::{db::HirDatabase, HasAttrs, HasVisibility, Name, StructKind}; |
4 | use itertools::Itertools; | 4 | use itertools::Itertools; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
@@ -27,7 +27,8 @@ pub(crate) fn render_struct_pat( | |||
27 | // Matching a struct without matching its fields is pointless, unlike matching a Variant without its fields | 27 | // Matching a struct without matching its fields is pointless, unlike matching a Variant without its fields |
28 | return None; | 28 | return None; |
29 | } | 29 | } |
30 | let fields_omitted = n_fields - fields.len() > 0; | 30 | let fields_omitted = |
31 | n_fields - fields.len() > 0 || strukt.attrs(ctx.db()).by_key("non_exhaustive").exists(); | ||
31 | 32 | ||
32 | let name = local_name.unwrap_or_else(|| strukt.name(ctx.db())).to_string(); | 33 | let name = local_name.unwrap_or_else(|| strukt.name(ctx.db())).to_string(); |
33 | let pat = render_pat(&ctx, &name, strukt.kind(ctx.db()), &fields, fields_omitted)?; | 34 | let pat = render_pat(&ctx, &name, strukt.kind(ctx.db()), &fields, fields_omitted)?; |
@@ -60,7 +61,8 @@ pub(crate) fn render_variant_pat( | |||
60 | .filter(|field| field.is_visible_from(ctx.db(), module)) | 61 | .filter(|field| field.is_visible_from(ctx.db(), module)) |
61 | .collect::<Vec<_>>(); | 62 | .collect::<Vec<_>>(); |
62 | 63 | ||
63 | let fields_omitted = n_fields - fields.len() > 0; | 64 | let fields_omitted = |
65 | n_fields - fields.len() > 0 || variant.attrs(ctx.db()).by_key("non_exhaustive").exists(); | ||
64 | 66 | ||
65 | let name = local_name.unwrap_or_else(|| variant.name(ctx.db())).to_string(); | 67 | let name = local_name.unwrap_or_else(|| variant.name(ctx.db())).to_string(); |
66 | let pat = render_pat(&ctx, &name, variant.kind(ctx.db()), &fields, fields_omitted)?; | 68 | let pat = render_pat(&ctx, &name, variant.kind(ctx.db()), &fields, fields_omitted)?; |