From dc63fea427280ff278bf89a8b9c78df606009910 Mon Sep 17 00:00:00 2001 From: Jade Date: Tue, 11 May 2021 05:06:33 -0700 Subject: Add basic support for array lengths in types This recognizes `let a = [1u8, 2, 3]` as having type `[u8; 3]` instead of the previous `[u8; _]`. Byte strings and `[0u8; 2]` kinds of range array declarations are unsupported as before. I don't know why a bunch of our rustc tests had single quotes inside strings un-escaped by `UPDATE_EXPECT=1 cargo t`, but I don't think it's bad? Maybe something in a nightly? --- crates/hir_ty/src/consts.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 crates/hir_ty/src/consts.rs (limited to 'crates/hir_ty/src/consts.rs') diff --git a/crates/hir_ty/src/consts.rs b/crates/hir_ty/src/consts.rs new file mode 100644 index 000000000..77d2a7a05 --- /dev/null +++ b/crates/hir_ty/src/consts.rs @@ -0,0 +1,20 @@ +//! Handling of concrete const values + +/// A concrete constant value +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum ConstScalar { + // for now, we only support the trivial case of constant evaluating the length of an array + Usize(usize), + + /// Case of an unknown value that rustc might know but we don't + Unknown, +} + +impl std::fmt::Display for ConstScalar { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + match self { + ConstScalar::Usize(us) => write!(fmt, "{}", us), + ConstScalar::Unknown => write!(fmt, "_"), + } + } +} -- cgit v1.2.3