diff options
author | Dawer <[email protected]> | 2021-04-30 15:12:04 +0100 |
---|---|---|
committer | Dawer <[email protected]> | 2021-05-31 20:03:46 +0100 |
commit | 5a8a0b62697c01ef881e7e2a0387e3649cab2034 (patch) | |
tree | e534317fe74f4cc90e33c6c7fb66a5e5289e6459 /crates/hir_ty/src/diagnostics/pattern/usefulness.rs | |
parent | b4f41973326a684844ffe23c5816e17d485b4203 (diff) |
Check enum patterns
Diffstat (limited to 'crates/hir_ty/src/diagnostics/pattern/usefulness.rs')
-rw-r--r-- | crates/hir_ty/src/diagnostics/pattern/usefulness.rs | 21 |
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 | ||
4 | use std::{cell::RefCell, iter::FromIterator, ops::Index, sync::Arc}; | 4 | use std::{cell::RefCell, iter::FromIterator, ops::Index, sync::Arc}; |
5 | 5 | ||
6 | use hir_def::{ModuleId, body::Body, expr::{ExprId, Pat, PatId}}; | 6 | use hir_def::{ |
7 | body::Body, | ||
8 | expr::{ExprId, Pat, PatId}, | ||
9 | HasModule, ModuleId, | ||
10 | }; | ||
7 | use la_arena::Arena; | 11 | use la_arena::Arena; |
8 | use once_cell::unsync::OnceCell; | 12 | use once_cell::unsync::OnceCell; |
9 | use rustc_hash::FxHashMap; | 13 | use 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 | } |