Skip to content

Use TyCtxt::mk_str instead of interned str #108008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
.1;
let len = s.len();
let cs = self.const_ptrcast(str_global.get_address(None),
self.type_ptr_to(self.layout_of(self.tcx.types.str_).gcc_type(self, true)),
self.type_ptr_to(self.layout_of(self.tcx.mk_str()).gcc_type(self, true)),
);
(cs, self.const_usize(len as u64))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let len = s.len();
let cs = consts::ptrcast(
str_global,
self.type_ptr_to(self.layout_of(self.tcx.types.str_).llvm_type(self)),
self.type_ptr_to(self.layout_of(self.tcx.mk_str()).llvm_type(self)),
);
(cs, self.const_usize(len as u64))
}
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,9 @@ where
let meta = Scalar::from_machine_usize(u64::try_from(str.len()).unwrap(), self);
let mplace = MemPlace { ptr: ptr.into(), meta: MemPlaceMeta::Meta(meta) };

let ty = self.tcx.mk_ref(
self.tcx.lifetimes.re_static,
ty::TypeAndMut { ty: self.tcx.types.str_, mutbl },
);
let ty = self
.tcx
.mk_ref(self.tcx.lifetimes.re_static, ty::TypeAndMut { ty: self.tcx.mk_str(), mutbl });
let layout = self.layout_of(ty).unwrap();
Ok(MPlaceTy { mplace, layout, align: layout.align.abi })
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
hir::PrimTy::Int(it) => tcx.mk_mach_int(ty::int_ty(it)),
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(ty::uint_ty(uit)),
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ty::float_ty(ft)),
hir::PrimTy::Str => tcx.types.str_,
hir::PrimTy::Str => tcx.mk_str(),
}
}
Res::Err => {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ pub struct CommonTypes<'tcx> {
pub u128: Ty<'tcx>,
pub f32: Ty<'tcx>,
pub f64: Ty<'tcx>,
pub str_: Ty<'tcx>,
pub never: Ty<'tcx>,
pub self_param: Ty<'tcx>,

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

trait_object_dummy_self: fresh_tys[0],
Expand Down Expand Up @@ -1696,9 +1694,13 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

pub fn mk_str(self) -> Ty<'tcx> {
self.mk_ty(ty::Str)
}

#[inline]
pub fn mk_static_str(self) -> Ty<'tcx> {
self.mk_imm_ref(self.lifetimes.re_static, self.types.str_)
self.mk_imm_ref(self.lifetimes.re_static, self.mk_str())
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
let re_erased = tcx.lifetimes.re_erased;
let ref_string = self.temp(tcx.mk_imm_ref(re_erased, ty), test.span);
let ref_str_ty = tcx.mk_imm_ref(re_erased, tcx.types.str_);
let ref_str_ty = tcx.mk_imm_ref(re_erased, tcx.mk_str());
let ref_str = self.temp(ref_str_ty, test.span);
let deref = tcx.require_lang_item(LangItem::Deref, None);
let method = trait_method(tcx, deref, sym::deref, [ty]);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
// See https://github.com/rust-lang/rust/issues/90703#issuecomment-1004263455
Some(match prim {
Bool => tcx.types.bool,
Str => tcx.types.str_,
Str => tcx.mk_str(),
Char => tcx.types.char,
Never => tcx.types.never,
I8 => tcx.types.i8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ fn is_to_string_on_string_like<'a>(
&& let GenericArgKind::Type(ty) = generic_arg.unpack()
&& let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref)
&& let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef)
&& (cx.get_associated_type(ty, deref_trait_id, "Target") == Some(cx.tcx.types.str_) ||
implements_trait(cx, ty, as_ref_trait_id, &[cx.tcx.types.str_.into()])) {
&& (cx.get_associated_type(ty, deref_trait_id, "Target").map_or(false, |ty| ty.is_str()) ||
implements_trait(cx, ty, as_ref_trait_id, &[cx.tcx.mk_str().into()])) {
true
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ enum DerefTy<'tcx> {
impl<'tcx> DerefTy<'tcx> {
fn ty(&self, cx: &LateContext<'tcx>) -> Ty<'tcx> {
match *self {
Self::Str => cx.tcx.types.str_,
Self::Str => cx.tcx.mk_str(),
Self::Path => cx.tcx.mk_adt(
cx.tcx.adt_def(cx.tcx.get_diagnostic_item(sym::Path).unwrap()),
List::empty(),
Expand Down