Skip to content

Commit 218b90f

Browse files
authored
Rollup merge of #72689 - lcnr:common_str, r=estebank
add str to common types I already expected this to be the case and it may slightly improve perf. Afaict if we ever want to change str into a lang item this would have to get reverted. As that would be fairly simple I don't believe this to cause any problems in the future.
2 parents 5c9cd82 + b3aa5e3 commit 218b90f

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/librustc_codegen_llvm/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
206206
let len = s.as_str().len();
207207
let cs = consts::ptrcast(
208208
self.const_cstr(s, false),
209-
self.type_ptr_to(self.layout_of(self.tcx.mk_str()).llvm_type(self)),
209+
self.type_ptr_to(self.layout_of(self.tcx.types.str_).llvm_type(self)),
210210
);
211211
(cs, self.const_usize(len as u64))
212212
}

src/librustc_middle/ty/context.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub struct CommonTypes<'tcx> {
143143
pub u128: Ty<'tcx>,
144144
pub f32: Ty<'tcx>,
145145
pub f64: Ty<'tcx>,
146+
pub str_: Ty<'tcx>,
146147
pub never: Ty<'tcx>,
147148
pub self_param: Ty<'tcx>,
148149

@@ -816,6 +817,7 @@ impl<'tcx> CommonTypes<'tcx> {
816817
u128: mk(Uint(ast::UintTy::U128)),
817818
f32: mk(Float(ast::FloatTy::F32)),
818819
f64: mk(Float(ast::FloatTy::F64)),
820+
str_: mk(Str),
819821
self_param: mk(ty::Param(ty::ParamTy { index: 0, name: kw::SelfUpper })),
820822

821823
trait_object_dummy_self: mk(Infer(ty::FreshTy(0))),
@@ -2149,14 +2151,9 @@ impl<'tcx> TyCtxt<'tcx> {
21492151
}
21502152
}
21512153

2152-
#[inline]
2153-
pub fn mk_str(self) -> Ty<'tcx> {
2154-
self.mk_ty(Str)
2155-
}
2156-
21572154
#[inline]
21582155
pub fn mk_static_str(self) -> Ty<'tcx> {
2159-
self.mk_imm_ref(self.lifetimes.re_static, self.mk_str())
2156+
self.mk_imm_ref(self.lifetimes.re_static, self.types.str_)
21602157
}
21612158

21622159
#[inline]

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2787,7 +2787,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27872787
hir::PrimTy::Int(it) => tcx.mk_mach_int(it),
27882788
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(uit),
27892789
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ft),
2790-
hir::PrimTy::Str => tcx.mk_str(),
2790+
hir::PrimTy::Str => tcx.types.str_,
27912791
}
27922792
}
27932793
Res::Err => {

0 commit comments

Comments
 (0)