aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/diagnostics/pattern/usefulness.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/diagnostics/pattern/usefulness.rs')
-rw-r--r--crates/hir_ty/src/diagnostics/pattern/usefulness.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/crates/hir_ty/src/diagnostics/pattern/usefulness.rs b/crates/hir_ty/src/diagnostics/pattern/usefulness.rs
index 4b55aee97..2df87ccea 100644
--- a/crates/hir_ty/src/diagnostics/pattern/usefulness.rs
+++ b/crates/hir_ty/src/diagnostics/pattern/usefulness.rs
@@ -3,7 +3,11 @@
3 3
4use std::{cell::RefCell, iter::FromIterator, ops::Index, sync::Arc}; 4use std::{cell::RefCell, iter::FromIterator, ops::Index, sync::Arc};
5 5
6use hir_def::{ModuleId, body::Body, expr::{ExprId, Pat, PatId}}; 6use hir_def::{
7 body::Body,
8 expr::{ExprId, Pat, PatId},
9 HasModule, ModuleId,
10};
7use la_arena::Arena; 11use la_arena::Arena;
8use once_cell::unsync::OnceCell; 12use once_cell::unsync::OnceCell;
9use rustc_hash::FxHashMap; 13use rustc_hash::FxHashMap;
@@ -36,6 +40,21 @@ impl<'a> MatchCheckCtx<'a> {
36 false 40 false
37 } 41 }
38 42
43 /// Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.
44 pub(super) fn is_foreign_non_exhaustive_enum(&self, enum_id: hir_def::EnumId) -> bool {
45 let has_non_exhaustive_attr =
46 self.db.attrs(enum_id.into()).by_key("non_exhaustive").exists();
47 let is_local =
48 hir_def::AdtId::from(enum_id).module(self.db.upcast()).krate() == self.module.krate();
49 has_non_exhaustive_attr && !is_local
50 }
51
52 // Rust feature described as "Allows exhaustive pattern matching on types that contain uninhabited types."
53 pub(super) fn feature_exhaustive_patterns(&self) -> bool {
54 // TODO
55 false
56 }
57
39 pub(super) fn alloc_pat(&self, pat: Pat, ty: &Ty) -> PatId { 58 pub(super) fn alloc_pat(&self, pat: Pat, ty: &Ty) -> PatId {
40 self.pattern_arena.borrow_mut().alloc(pat, ty) 59 self.pattern_arena.borrow_mut().alloc(pat, ty)
41 } 60 }