aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/diagnostics/pattern.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/diagnostics/pattern.rs')
-rw-r--r--crates/hir_ty/src/diagnostics/pattern.rs19
1 files changed, 19 insertions, 0 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)]