aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/diagnostics/pattern.rs
diff options
context:
space:
mode:
authorDawer <[email protected]>2021-05-06 15:39:27 +0100
committerDawer <[email protected]>2021-05-31 20:03:47 +0100
commitcf6f989a8d638b76ec7e14d00f7ed095b20ffed6 (patch)
tree52c47f879dd977dae318c4719d5b3846639f4f1c /crates/hir_ty/src/diagnostics/pattern.rs
parentd6d77e8a35cb2ac63b877f73bdf0ea6e6a1578e4 (diff)
Lower bool literals
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)]