diff options
author | Jade <[email protected]> | 2021-05-12 13:44:01 +0100 |
---|---|---|
committer | Jade <[email protected]> | 2021-05-13 05:22:46 +0100 |
commit | 73023c0299d4adeada026648c3684621f129e038 (patch) | |
tree | 302ca449ae51a546d808d93037134af9c470d6b5 /crates/hir_ty/src/infer | |
parent | 8b147624ff906a11134d2e18be071c6cb8ec4beb (diff) |
Support length for ByteStrings
I am not confident that my added byte string parsing is right.
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 5e9420752..46e4777a4 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -16,7 +16,7 @@ use stdx::always; | |||
16 | use syntax::ast::RangeOp; | 16 | use syntax::ast::RangeOp; |
17 | 17 | ||
18 | use crate::{ | 18 | use crate::{ |
19 | autoderef, dummy_usize_const, | 19 | autoderef, |
20 | lower::lower_to_chalk_mutability, | 20 | lower::lower_to_chalk_mutability, |
21 | mapping::from_chalk, | 21 | mapping::from_chalk, |
22 | method_resolution, op, | 22 | method_resolution, op, |
@@ -24,8 +24,9 @@ use crate::{ | |||
24 | static_lifetime, to_chalk_trait_id, | 24 | static_lifetime, to_chalk_trait_id, |
25 | traits::FnTrait, | 25 | traits::FnTrait, |
26 | utils::{generics, Generics}, | 26 | utils::{generics, Generics}, |
27 | AdtId, Binders, CallableDefId, ConstValue, FnPointer, FnSig, FnSubst, InEnvironment, Interner, | 27 | AdtId, Binders, CallableDefId, ConcreteConst, ConstValue, FnPointer, FnSig, FnSubst, |
28 | ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind, | 28 | InEnvironment, Interner, ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, |
29 | TyBuilder, TyExt, TyKind, | ||
29 | }; | 30 | }; |
30 | 31 | ||
31 | use super::{ | 32 | use super::{ |
@@ -758,11 +759,18 @@ impl<'a> InferenceContext<'a> { | |||
758 | TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(&Interner)) | 759 | TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(&Interner)) |
759 | .intern(&Interner) | 760 | .intern(&Interner) |
760 | } | 761 | } |
761 | Literal::ByteString(..) => { | 762 | Literal::ByteString(bs) => { |
762 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); | 763 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); |
763 | 764 | ||
764 | let array_type = | 765 | let len = ConstData { |
765 | TyKind::Array(byte_type, dummy_usize_const()).intern(&Interner); | 766 | ty: TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner), |
767 | value: ConstValue::Concrete(ConcreteConst { | ||
768 | interned: ConstScalar::Usize(bs.len() as u64), | ||
769 | }), | ||
770 | } | ||
771 | .intern(&Interner); | ||
772 | |||
773 | let array_type = TyKind::Array(byte_type, len).intern(&Interner); | ||
766 | TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner) | 774 | TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner) |
767 | } | 775 | } |
768 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), | 776 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), |