diff options
Diffstat (limited to 'crates/hir_ty/src/consts.rs')
-rw-r--r-- | crates/hir_ty/src/consts.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crates/hir_ty/src/consts.rs b/crates/hir_ty/src/consts.rs new file mode 100644 index 000000000..0044b1cff --- /dev/null +++ b/crates/hir_ty/src/consts.rs | |||
@@ -0,0 +1,21 @@ | |||
1 | //! Handling of concrete const values | ||
2 | |||
3 | /// A concrete constant value | ||
4 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
5 | pub enum ConstScalar { | ||
6 | // for now, we only support the trivial case of constant evaluating the length of an array | ||
7 | // Note that this is u64 because the target usize may be bigger than our usize | ||
8 | Usize(u64), | ||
9 | |||
10 | /// Case of an unknown value that rustc might know but we don't | ||
11 | Unknown, | ||
12 | } | ||
13 | |||
14 | impl std::fmt::Display for ConstScalar { | ||
15 | fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { | ||
16 | match self { | ||
17 | ConstScalar::Usize(us) => write!(fmt, "{}", us), | ||
18 | ConstScalar::Unknown => write!(fmt, "_"), | ||
19 | } | ||
20 | } | ||
21 | } | ||