aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/infer/expr.rs20
-rw-r--r--crates/hir_ty/src/tests/simple.rs4
2 files changed, 16 insertions, 8 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;
16use syntax::ast::RangeOp; 16use syntax::ast::RangeOp;
17 17
18use crate::{ 18use 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
31use super::{ 32use 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),
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs
index 19775a4ec..79445a12d 100644
--- a/crates/hir_ty/src/tests/simple.rs
+++ b/crates/hir_ty/src/tests/simple.rs
@@ -496,7 +496,7 @@ fn infer_literals() {
496 26..30 '5f32': f32 496 26..30 '5f32': f32
497 36..40 '5f64': f64 497 36..40 '5f64': f64
498 46..53 '"hello"': &str 498 46..53 '"hello"': &str
499 59..67 'b"bytes"': &[u8; _] 499 59..67 'b"bytes"': &[u8; 5]
500 73..76 ''c'': char 500 73..76 ''c'': char
501 82..86 'b'b'': u8 501 82..86 'b'b'': u8
502 92..96 '3.14': f64 502 92..96 '3.14': f64
@@ -504,7 +504,7 @@ fn infer_literals() {
504 112..117 'false': bool 504 112..117 'false': bool
505 123..127 'true': bool 505 123..127 'true': bool
506 133..197 'r#" ... "#': &str 506 133..197 'r#" ... "#': &str
507 203..213 'br#"yolo"#': &[u8; _] 507 203..213 'br#"yolo"#': &[u8; 4]
508 "##]], 508 "##]],
509 ); 509 );
510} 510}