aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/diagnostics/pattern.rs19
-rw-r--r--crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs23
2 files changed, 29 insertions, 13 deletions
diff --git a/crates/hir_ty/src/diagnostics/pattern.rs b/crates/hir_ty/src/diagnostics/pattern.rs
index 7b0b63d0b..14dd736a6 100644
--- a/crates/hir_ty/src/diagnostics/pattern.rs
+++ b/crates/hir_ty/src/diagnostics/pattern.rs
@@ -67,6 +67,11 @@ pub enum PatKind {
67 subpattern: Pat, 67 subpattern: Pat,
68 }, 68 },
69 69
70 // only bool for now
71 LiteralBool {
72 value: bool,
73 },
74
70 /// An or-pattern, e.g. `p | q`. 75 /// An or-pattern, e.g. `p | q`.
71 /// Invariant: `pats.len() >= 2`. 76 /// Invariant: `pats.len() >= 2`.
72 Or { 77 Or {
@@ -99,6 +104,8 @@ impl<'a> PatCtxt<'a> {
99 let kind = match self.body[pat] { 104 let kind = match self.body[pat] {
100 hir_def::expr::Pat::Wild => PatKind::Wild, 105 hir_def::expr::Pat::Wild => PatKind::Wild,
101 106
107 hir_def::expr::Pat::Lit(expr) => self.lower_lit(expr),
108
102 hir_def::expr::Pat::Path(ref path) => { 109 hir_def::expr::Pat::Path(ref path) => {
103 return self.lower_path(pat, path); 110 return self.lower_path(pat, path);
104 } 111 }
@@ -211,6 +218,18 @@ impl<'a> PatCtxt<'a> {
211 } 218 }
212 } 219 }
213 } 220 }
221
222 fn lower_lit(&mut self, expr: hir_def::expr::ExprId) -> PatKind {
223 use hir_def::expr::{Expr, Literal::Bool};
224
225 match self.body[expr] {
226 Expr::Literal(Bool(value)) => PatKind::LiteralBool { value },
227 _ => {
228 self.errors.push(PatternError::Unimplemented);
229 PatKind::Wild
230 }
231 }
232 }
214} 233}
215 234
216#[cfg(test)] 235#[cfg(test)]
diff --git a/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs b/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs
index 1319745ce..91b9c7184 100644
--- a/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs
+++ b/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs
@@ -275,14 +275,8 @@ impl Constructor {
275 PatKind::Binding { .. } | PatKind::Wild => Wildcard, 275 PatKind::Binding { .. } | PatKind::Wild => Wildcard,
276 PatKind::Leaf { .. } | PatKind::Deref { .. } => Single, 276 PatKind::Leaf { .. } | PatKind::Deref { .. } => Single,
277 &PatKind::Variant { enum_variant, .. } => Variant(enum_variant), 277 &PatKind::Variant { enum_variant, .. } => Variant(enum_variant),
278 278 &PatKind::LiteralBool { value } => IntRange(IntRange::from_bool(value)),
279 //Todo
280 // &Pat::Lit(expr_id) => match cx.body[expr_id] {
281 // Expr::Literal(Literal::Bool(val)) => IntRange(IntRange::from_bool(val)),
282 // _ => todo!(),
283 // },
284 PatKind::Or { .. } => panic!("bug: Or-pattern should have been expanded earlier on."), 279 PatKind::Or { .. } => panic!("bug: Or-pattern should have been expanded earlier on."),
285 pat => todo!("Constructor::from_pat {:?}", pat),
286 } 280 }
287 } 281 }
288 282
@@ -690,7 +684,7 @@ impl Fields {
690 let mut subpatterns = 684 let mut subpatterns =
691 subpatterns_and_indices.iter().map(|&(_, p)| pcx.cx.pattern_arena.borrow()[p].clone()); 685 subpatterns_and_indices.iter().map(|&(_, p)| pcx.cx.pattern_arena.borrow()[p].clone());
692 // FIXME(iDawer) witnesses are not yet used 686 // FIXME(iDawer) witnesses are not yet used
693 const UNIMPLEMENTED: PatKind = PatKind::Wild; 687 const UNHANDLED: PatKind = PatKind::Wild;
694 688
695 let pat = match ctor { 689 let pat = match ctor {
696 Single | Variant(_) => match pcx.ty.kind(&Interner) { 690 Single | Variant(_) => match pcx.ty.kind(&Interner) {
@@ -728,10 +722,10 @@ impl Fields {
728 } 722 }
729 _ => PatKind::Wild, 723 _ => PatKind::Wild,
730 }, 724 },
731 Constructor::Slice(slice) => UNIMPLEMENTED, 725 Constructor::Slice(slice) => UNHANDLED,
732 Str(_) => UNIMPLEMENTED, 726 Str(_) => UNHANDLED,
733 FloatRange(..) => UNIMPLEMENTED, 727 FloatRange(..) => UNHANDLED,
734 Constructor::IntRange(_) => UNIMPLEMENTED, 728 Constructor::IntRange(_) => UNHANDLED,
735 NonExhaustive => PatKind::Wild, 729 NonExhaustive => PatKind::Wild,
736 Wildcard => return Pat::wildcard_from_ty(pcx.ty), 730 Wildcard => return Pat::wildcard_from_ty(pcx.ty),
737 Opaque => panic!("bug: we should not try to apply an opaque constructor"), 731 Opaque => panic!("bug: we should not try to apply an opaque constructor"),
@@ -855,7 +849,10 @@ impl Fields {
855 self.replace_with_fieldpats(subpatterns) 849 self.replace_with_fieldpats(subpatterns)
856 } 850 }
857 851
858 PatKind::Wild | PatKind::Binding { .. } | PatKind::Or { .. } => self.clone(), 852 PatKind::Wild
853 | PatKind::Binding { .. }
854 | PatKind::LiteralBool { .. }
855 | PatKind::Or { .. } => self.clone(),
859 } 856 }
860 } 857 }
861} 858}