Skip to content

Commit e15212f

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 0b6f079 commit e15212f

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

compiler/rustc_hir/src/lang_items.rs

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ symbols! {
478478
const_raw_ptr_to_usize_cast,
479479
const_refs_to_cell,
480480
const_slice_ptr,
481+
const_str_ptr,
481482
const_trait_bound_opt_out,
482483
const_trait_impl,
483484
const_transmute,
@@ -864,6 +865,7 @@ symbols! {
864865
must_use,
865866
mut_ptr,
866867
mut_slice_ptr,
868+
mut_str_ptr,
867869
naked,
868870
naked_functions,
869871
name,

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

Lines changed: 12 additions & 7 deletions
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

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

0 commit comments

Comments
 (0)