aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/consts.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-12 15:49:43 +0100
committerGitHub <[email protected]>2021-05-12 15:49:43 +0100
commit312f1fe20a6a0a8e69834c66f51b9abc9db5e0ce (patch)
tree5b50f7359a6eaf482f01ade44dc12fd7bd1594ba /crates/hir_ty/src/consts.rs
parent1c927d2f8efdf8488d319b335db70b120dc11c37 (diff)
parentf28c053c677203f4dd101222460081dd97c1f440 (diff)
Merge #8799
8799: Add basic support for array lengths in types r=flodiebold a=lf- 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? Co-authored-by: Jade <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/consts.rs')
-rw-r--r--crates/hir_ty/src/consts.rs21
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)]
5pub 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
14impl 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}