Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/expr.rs')
-rw-r--r--crates/hir-ty/src/infer/expr.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index 385766fdad..56438866de 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -13,7 +13,7 @@ use hir_def::{
hir::{
ArithOp, Array, BinaryOp, ClosureKind, Expr, ExprId, LabelId, Literal, Statement, UnaryOp,
},
- lang_item::LangItem,
+ lang_item::{LangItem, LangItemTarget},
path::{GenericArg, GenericArgs},
BlockId, ConstParamId, FieldId, ItemContainerId, Lookup,
};
@@ -815,7 +815,7 @@ impl<'a> InferenceContext<'a> {
Expr::Array(array) => self.infer_expr_array(array, expected),
Expr::Literal(lit) => match lit {
Literal::Bool(..) => self.result.standard_types.bool_.clone(),
- Literal::String(..) | Literal::CString(..) => {
+ Literal::String(..) => {
TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(Interner))
.intern(Interner)
}
@@ -831,6 +831,20 @@ impl<'a> InferenceContext<'a> {
let array_type = TyKind::Array(byte_type, len).intern(Interner);
TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(Interner)
}
+ Literal::CString(..) => TyKind::Ref(
+ Mutability::Not,
+ static_lifetime(),
+ self.resolve_lang_item(LangItem::CStr)
+ .and_then(LangItemTarget::as_struct)
+ .map_or_else(
+ || self.err_ty(),
+ |strukt| {
+ TyKind::Adt(AdtId(strukt.into()), Substitution::empty(Interner))
+ .intern(Interner)
+ },
+ ),
+ )
+ .intern(Interner),
Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(Interner),
Literal::Int(_v, ty) => match ty {
Some(int_ty) => {