Auto merge of #14837 - Veykril:rustc-lexer, r=Veykril

Support c string literals
This commit is contained in:
bors 2023-05-18 11:55:38 +00:00
commit 9ce95674e8
24 changed files with 374 additions and 155 deletions

View file

@ -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,
};
@ -832,6 +832,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) => {