Skip to content

Commit 33ecad4

Browse files
committed
Create non-exhaustive patterns for non_exhaustive attributed items
1 parent a5874a3 commit 33ecad4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crates/completion/src/render/pattern.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Renderer for patterns.
22
3-
use hir::{db::HirDatabase, HasVisibility, Name, StructKind};
3+
use hir::{db::HirDatabase, HasAttrs, HasVisibility, Name, StructKind};
44
use itertools::Itertools;
55

66
use crate::{
@@ -27,7 +27,8 @@ pub(crate) fn render_struct_pat(
2727
// Matching a struct without matching its fields is pointless, unlike matching a Variant without its fields
2828
return None;
2929
}
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();
3132

3233
let name = local_name.unwrap_or_else(|| strukt.name(ctx.db())).to_string();
3334
let pat = render_pat(&ctx, &name, strukt.kind(ctx.db()), &fields, fields_omitted)?;
@@ -60,7 +61,8 @@ pub(crate) fn render_variant_pat(
6061
.filter(|field| field.is_visible_from(ctx.db(), module))
6162
.collect::<Vec<_>>();
6263

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();
6466

6567
let name = local_name.unwrap_or_else(|| variant.name(ctx.db())).to_string();
6668
let pat = render_pat(&ctx, &name, variant.kind(ctx.db()), &fields, fields_omitted)?;

0 commit comments

Comments
 (0)