Skip to content

Commit ab96836

Browse files
committed
Add const_str_ptr and mut_str_ptr lang items
These items allow to make inherent impls for `*const str` and `*mut str`.
1 parent d2e78d8 commit ab96836

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

compiler/rustc_hir/src/lang_items.rs

+2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ language_item_table! {
184184
ConstPtr, sym::const_ptr, const_ptr_impl, Target::Impl, GenericRequirement::None;
185185
MutPtr, sym::mut_ptr, mut_ptr_impl, Target::Impl, GenericRequirement::None;
186186
ConstSlicePtr, sym::const_slice_ptr, const_slice_ptr_impl, Target::Impl, GenericRequirement::None;
187+
ConstStrPtr, sym::const_str_ptr, const_str_ptr_impl, Target::Impl, GenericRequirement::None;
187188
MutSlicePtr, sym::mut_slice_ptr, mut_slice_ptr_impl, Target::Impl, GenericRequirement::None;
189+
MutStrPtr, sym::mut_str_ptr, mut_str_ptr_impl, Target::Impl, GenericRequirement::None;
188190
I8, sym::i8, i8_impl, Target::Impl, GenericRequirement::None;
189191
I16, sym::i16, i16_impl, Target::Impl, GenericRequirement::None;
190192
I32, sym::i32, i32_impl, Target::Impl, GenericRequirement::None;

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ symbols! {
458458
const_raw_ptr_to_usize_cast,
459459
const_refs_to_cell,
460460
const_slice_ptr,
461+
const_str_ptr,
461462
const_trait_bound_opt_out,
462463
const_trait_impl,
463464
const_transmute,
@@ -839,6 +840,7 @@ symbols! {
839840
must_use,
840841
mut_ptr,
841842
mut_slice_ptr,
843+
mut_str_ptr,
842844
naked,
843845
naked_functions,
844846
name,

compiler/rustc_typeck/src/check/method/probe.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -680,16 +680,21 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
680680
self.assemble_inherent_impl_for_primitive(lang_def_id);
681681
}
682682
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl }) => {
683-
let (lang_def_id1, lang_def_id2) = match mutbl {
684-
hir::Mutability::Not => {
685-
(lang_items.const_ptr_impl(), lang_items.const_slice_ptr_impl())
686-
}
687-
hir::Mutability::Mut => {
688-
(lang_items.mut_ptr_impl(), lang_items.mut_slice_ptr_impl())
689-
}
683+
let (lang_def_id1, lang_def_id2, lang_def_id3) = match mutbl {
684+
hir::Mutability::Not => (
685+
lang_items.const_ptr_impl(),
686+
lang_items.const_slice_ptr_impl(),
687+
lang_items.const_str_ptr_impl(),
688+
),
689+
hir::Mutability::Mut => (
690+
lang_items.mut_ptr_impl(),
691+
lang_items.mut_slice_ptr_impl(),
692+
lang_items.mut_str_ptr_impl(),
693+
),
690694
};
691695
self.assemble_inherent_impl_for_primitive(lang_def_id1);
692696
self.assemble_inherent_impl_for_primitive(lang_def_id2);
697+
self.assemble_inherent_impl_for_primitive(lang_def_id3);
693698
}
694699
ty::Int(i) => {
695700
let lang_def_id = match i {

compiler/rustc_typeck/src/coherence/inherent_impls.rs

+26
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
150150
assoc_items,
151151
);
152152
}
153+
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Not })
154+
if matches!(inner.kind(), ty::Str) =>
155+
{
156+
self.check_primitive_impl(
157+
item.def_id,
158+
lang_items.const_str_ptr_impl(),
159+
None,
160+
"const_str_ptr",
161+
"*const str",
162+
item.span,
163+
assoc_items,
164+
);
165+
}
153166
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Mut })
154167
if matches!(inner.kind(), ty::Slice(_)) =>
155168
{
@@ -163,6 +176,19 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
163176
assoc_items,
164177
);
165178
}
179+
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Mut })
180+
if matches!(inner.kind(), ty::Str) =>
181+
{
182+
self.check_primitive_impl(
183+
item.def_id,
184+
lang_items.mut_str_ptr_impl(),
185+
None,
186+
"mut_str_ptr",
187+
"*mut str",
188+
item.span,
189+
assoc_items,
190+
);
191+
}
166192
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => {
167193
self.check_primitive_impl(
168194
item.def_id,

0 commit comments

Comments
 (0)