Skip to content

Commit 86d3b82

Browse files
Use TyCtxt::mk_str instead of interned str
1 parent 0b439b1 commit 86d3b82

File tree

9 files changed

+16
-15
lines changed

9 files changed

+16
-15
lines changed

compiler/rustc_codegen_gcc/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
133133
.1;
134134
let len = s.len();
135135
let cs = self.const_ptrcast(str_global.get_address(None),
136-
self.type_ptr_to(self.layout_of(self.tcx.types.str_).gcc_type(self, true)),
136+
self.type_ptr_to(self.layout_of(self.tcx.mk_str()).gcc_type(self, true)),
137137
);
138138
(cs, self.const_usize(len as u64))
139139
}

compiler/rustc_codegen_llvm/src/common.rs

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

compiler/rustc_const_eval/src/interpret/place.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,9 @@ where
759759
let meta = Scalar::from_machine_usize(u64::try_from(str.len()).unwrap(), self);
760760
let mplace = MemPlace { ptr: ptr.into(), meta: MemPlaceMeta::Meta(meta) };
761761

762-
let ty = self.tcx.mk_ref(
763-
self.tcx.lifetimes.re_static,
764-
ty::TypeAndMut { ty: self.tcx.types.str_, mutbl },
765-
);
762+
let ty = self
763+
.tcx
764+
.mk_ref(self.tcx.lifetimes.re_static, ty::TypeAndMut { ty: self.tcx.mk_str(), mutbl });
766765
let layout = self.layout_of(ty).unwrap();
767766
Ok(MPlaceTy { mplace, layout, align: layout.align.abi })
768767
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2819,7 +2819,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28192819
hir::PrimTy::Int(it) => tcx.mk_mach_int(ty::int_ty(it)),
28202820
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(ty::uint_ty(uit)),
28212821
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ty::float_ty(ft)),
2822-
hir::PrimTy::Str => tcx.types.str_,
2822+
hir::PrimTy::Str => tcx.mk_str(),
28232823
}
28242824
}
28252825
Res::Err => {

compiler/rustc_middle/src/ty/context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ pub struct CommonTypes<'tcx> {
264264
pub u128: Ty<'tcx>,
265265
pub f32: Ty<'tcx>,
266266
pub f64: Ty<'tcx>,
267-
pub str_: Ty<'tcx>,
268267
pub never: Ty<'tcx>,
269268
pub self_param: Ty<'tcx>,
270269

@@ -335,7 +334,6 @@ impl<'tcx> CommonTypes<'tcx> {
335334
u128: mk(Uint(ty::UintTy::U128)),
336335
f32: mk(Float(ty::FloatTy::F32)),
337336
f64: mk(Float(ty::FloatTy::F64)),
338-
str_: mk(Str),
339337
self_param: mk(ty::Param(ty::ParamTy { index: 0, name: kw::SelfUpper })),
340338

341339
trait_object_dummy_self: fresh_tys[0],
@@ -1696,9 +1694,13 @@ impl<'tcx> TyCtxt<'tcx> {
16961694
}
16971695
}
16981696

1697+
pub fn mk_str(self) -> Ty<'tcx> {
1698+
self.mk_ty(ty::Str)
1699+
}
1700+
16991701
#[inline]
17001702
pub fn mk_static_str(self) -> Ty<'tcx> {
1701-
self.mk_imm_ref(self.lifetimes.re_static, self.types.str_)
1703+
self.mk_imm_ref(self.lifetimes.re_static, self.mk_str())
17021704
}
17031705

17041706
#[inline]

compiler/rustc_mir_build/src/build/matches/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
245245
}
246246
let re_erased = tcx.lifetimes.re_erased;
247247
let ref_string = self.temp(tcx.mk_imm_ref(re_erased, ty), test.span);
248-
let ref_str_ty = tcx.mk_imm_ref(re_erased, tcx.types.str_);
248+
let ref_str_ty = tcx.mk_imm_ref(re_erased, tcx.mk_str());
249249
let ref_str = self.temp(ref_str_ty, test.span);
250250
let deref = tcx.require_lang_item(LangItem::Deref, None);
251251
let method = trait_method(tcx, deref, sym::deref, [ty]);

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
518518
// See https://github.com/rust-lang/rust/issues/90703#issuecomment-1004263455
519519
Some(match prim {
520520
Bool => tcx.types.bool,
521-
Str => tcx.types.str_,
521+
Str => tcx.mk_str(),
522522
Char => tcx.types.char,
523523
Never => tcx.types.never,
524524
I8 => tcx.types.i8,

src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ fn is_to_string_on_string_like<'a>(
497497
&& let GenericArgKind::Type(ty) = generic_arg.unpack()
498498
&& let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref)
499499
&& let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef)
500-
&& (cx.get_associated_type(ty, deref_trait_id, "Target") == Some(cx.tcx.types.str_) ||
501-
implements_trait(cx, ty, as_ref_trait_id, &[cx.tcx.types.str_.into()])) {
500+
&& (cx.get_associated_type(ty, deref_trait_id, "Target").map_or(false, |ty| ty.is_str()) ||
501+
implements_trait(cx, ty, as_ref_trait_id, &[cx.tcx.mk_str().into()])) {
502502
true
503503
} else {
504504
false

src/tools/clippy/clippy_lints/src/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ enum DerefTy<'tcx> {
385385
impl<'tcx> DerefTy<'tcx> {
386386
fn ty(&self, cx: &LateContext<'tcx>) -> Ty<'tcx> {
387387
match *self {
388-
Self::Str => cx.tcx.types.str_,
388+
Self::Str => cx.tcx.mk_str(),
389389
Self::Path => cx.tcx.mk_adt(
390390
cx.tcx.adt_def(cx.tcx.get_diagnostic_item(sym::Path).unwrap()),
391391
List::empty(),

0 commit comments

Comments
 (0)