mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
fix: completes non exhaustive variant within the defining crate
This commit is contained in:
parent
6fc5c3cd21
commit
472ae16bfb
3 changed files with 64 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
//! Code common to structs, unions, and enum variants.
|
||||
|
||||
use crate::context::CompletionContext;
|
||||
use hir::{db::HirDatabase, HasAttrs, HasVisibility, HirDisplay, StructKind};
|
||||
use hir::{db::HirDatabase, HasAttrs, HasCrate, HasVisibility, HirDisplay, StructKind};
|
||||
use ide_db::SnippetCap;
|
||||
use itertools::Itertools;
|
||||
use syntax::SmolStr;
|
||||
|
@ -70,7 +70,7 @@ pub(crate) fn render_tuple_lit(
|
|||
pub(crate) fn visible_fields(
|
||||
ctx: &CompletionContext,
|
||||
fields: &[hir::Field],
|
||||
item: impl HasAttrs,
|
||||
item: impl HasAttrs + HasCrate + Copy,
|
||||
) -> Option<(Vec<hir::Field>, bool)> {
|
||||
let module = ctx.module;
|
||||
let n_fields = fields.len();
|
||||
|
@ -79,9 +79,10 @@ pub(crate) fn visible_fields(
|
|||
.filter(|field| field.is_visible_from(ctx.db, module))
|
||||
.copied()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let fields_omitted =
|
||||
n_fields - fields.len() > 0 || item.attrs(ctx.db).by_key("non_exhaustive").exists();
|
||||
let has_invisible_field = n_fields - fields.len() > 0;
|
||||
let is_foreign_non_exhaustive = item.attrs(ctx.db).by_key("non_exhaustive").exists()
|
||||
&& item.krate(ctx.db) != module.krate();
|
||||
let fields_omitted = has_invisible_field || is_foreign_non_exhaustive;
|
||||
Some((fields, fields_omitted))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue