diff options
author | Jade <[email protected]> | 2021-05-11 13:06:33 +0100 |
---|---|---|
committer | Jade <[email protected]> | 2021-05-11 13:25:19 +0100 |
commit | dc63fea427280ff278bf89a8b9c78df606009910 (patch) | |
tree | 5fb6eae3df58a7c5bc3bc5a1220dd9a5d6d3ea86 /crates/hir_ty/src/interner.rs | |
parent | 77f0c92fd8311bccc001ddaf9eb72662d35e9836 (diff) |
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?
Diffstat (limited to 'crates/hir_ty/src/interner.rs')
-rw-r--r-- | crates/hir_ty/src/interner.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/hir_ty/src/interner.rs b/crates/hir_ty/src/interner.rs index a1656115d..4cbc9cd4f 100644 --- a/crates/hir_ty/src/interner.rs +++ b/crates/hir_ty/src/interner.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Implementation of the Chalk `Interner` trait, which allows customizing the | 1 | //! Implementation of the Chalk `Interner` trait, which allows customizing the |
2 | //! representation of the various objects Chalk deals with (types, goals etc.). | 2 | //! representation of the various objects Chalk deals with (types, goals etc.). |
3 | 3 | ||
4 | use crate::{chalk_db, tls, GenericArg}; | 4 | use crate::{chalk_db, consts::ConstScalar, tls, GenericArg}; |
5 | use base_db::salsa::InternId; | 5 | use base_db::salsa::InternId; |
6 | use chalk_ir::{Goal, GoalData}; | 6 | use chalk_ir::{Goal, GoalData}; |
7 | use hir_def::{ | 7 | use hir_def::{ |
@@ -31,6 +31,7 @@ impl_internable!( | |||
31 | InternedWrapper<chalk_ir::TyData<Interner>>, | 31 | InternedWrapper<chalk_ir::TyData<Interner>>, |
32 | InternedWrapper<chalk_ir::LifetimeData<Interner>>, | 32 | InternedWrapper<chalk_ir::LifetimeData<Interner>>, |
33 | InternedWrapper<chalk_ir::ConstData<Interner>>, | 33 | InternedWrapper<chalk_ir::ConstData<Interner>>, |
34 | InternedWrapper<ConstScalar>, | ||
34 | InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Interner>>>, | 35 | InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Interner>>>, |
35 | InternedWrapper<Vec<chalk_ir::ProgramClause<Interner>>>, | 36 | InternedWrapper<Vec<chalk_ir::ProgramClause<Interner>>>, |
36 | InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Interner>>>, | 37 | InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Interner>>>, |
@@ -41,7 +42,7 @@ impl chalk_ir::interner::Interner for Interner { | |||
41 | type InternedType = Interned<InternedWrapper<chalk_ir::TyData<Interner>>>; | 42 | type InternedType = Interned<InternedWrapper<chalk_ir::TyData<Interner>>>; |
42 | type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>; | 43 | type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>; |
43 | type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>; | 44 | type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>; |
44 | type InternedConcreteConst = (); | 45 | type InternedConcreteConst = ConstScalar; |
45 | type InternedGenericArg = chalk_ir::GenericArgData<Self>; | 46 | type InternedGenericArg = chalk_ir::GenericArgData<Self>; |
46 | type InternedGoal = Arc<GoalData<Self>>; | 47 | type InternedGoal = Arc<GoalData<Self>>; |
47 | type InternedGoals = Vec<Goal<Self>>; | 48 | type InternedGoals = Vec<Goal<Self>>; |
@@ -245,10 +246,15 @@ impl chalk_ir::interner::Interner for Interner { | |||
245 | fn const_eq( | 246 | fn const_eq( |
246 | &self, | 247 | &self, |
247 | _ty: &Self::InternedType, | 248 | _ty: &Self::InternedType, |
248 | _c1: &Self::InternedConcreteConst, | 249 | c1: &Self::InternedConcreteConst, |
249 | _c2: &Self::InternedConcreteConst, | 250 | c2: &Self::InternedConcreteConst, |
250 | ) -> bool { | 251 | ) -> bool { |
251 | true | 252 | match (c1, c2) { |
253 | (&ConstScalar::Usize(a), &ConstScalar::Usize(b)) => a == b, | ||
254 | // we were previously assuming this to be true, I'm not whether true or false on | ||
255 | // unknown values is safer. | ||
256 | (_, _) => true, | ||
257 | } | ||
252 | } | 258 | } |
253 | 259 | ||
254 | fn intern_generic_arg( | 260 | fn intern_generic_arg( |