Skip to content
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

Add str pointer methods #85816

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add const_str_ptr and mut_str_ptr lang items
These items allow to make inherent impls for `*const str` and `*mut str`.
WaffleLapkin committed Sep 4, 2021

Verified

This commit was signed with the committer’s verified signature.
Cruikshanks Alan Cruikshanks
commit ab968360363ff7ac50fad8080e9fcfe91d103dc8
2 changes: 2 additions & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
@@ -184,7 +184,9 @@ language_item_table! {
ConstPtr, sym::const_ptr, const_ptr_impl, Target::Impl, GenericRequirement::None;
MutPtr, sym::mut_ptr, mut_ptr_impl, Target::Impl, GenericRequirement::None;
ConstSlicePtr, sym::const_slice_ptr, const_slice_ptr_impl, Target::Impl, GenericRequirement::None;
ConstStrPtr, sym::const_str_ptr, const_str_ptr_impl, Target::Impl, GenericRequirement::None;
MutSlicePtr, sym::mut_slice_ptr, mut_slice_ptr_impl, Target::Impl, GenericRequirement::None;
MutStrPtr, sym::mut_str_ptr, mut_str_ptr_impl, Target::Impl, GenericRequirement::None;
I8, sym::i8, i8_impl, Target::Impl, GenericRequirement::None;
I16, sym::i16, i16_impl, Target::Impl, GenericRequirement::None;
I32, sym::i32, i32_impl, Target::Impl, GenericRequirement::None;
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -458,6 +458,7 @@ symbols! {
const_raw_ptr_to_usize_cast,
const_refs_to_cell,
const_slice_ptr,
const_str_ptr,
const_trait_bound_opt_out,
const_trait_impl,
const_transmute,
@@ -839,6 +840,7 @@ symbols! {
must_use,
mut_ptr,
mut_slice_ptr,
mut_str_ptr,
naked,
naked_functions,
name,
19 changes: 12 additions & 7 deletions compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
@@ -680,16 +680,21 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl }) => {
let (lang_def_id1, lang_def_id2) = match mutbl {
hir::Mutability::Not => {
(lang_items.const_ptr_impl(), lang_items.const_slice_ptr_impl())
}
hir::Mutability::Mut => {
(lang_items.mut_ptr_impl(), lang_items.mut_slice_ptr_impl())
}
let (lang_def_id1, lang_def_id2, lang_def_id3) = match mutbl {
hir::Mutability::Not => (
lang_items.const_ptr_impl(),
lang_items.const_slice_ptr_impl(),
lang_items.const_str_ptr_impl(),
),
hir::Mutability::Mut => (
lang_items.mut_ptr_impl(),
lang_items.mut_slice_ptr_impl(),
lang_items.mut_str_ptr_impl(),
),
};
self.assemble_inherent_impl_for_primitive(lang_def_id1);
self.assemble_inherent_impl_for_primitive(lang_def_id2);
self.assemble_inherent_impl_for_primitive(lang_def_id3);
}
ty::Int(i) => {
let lang_def_id = match i {
26 changes: 26 additions & 0 deletions compiler/rustc_typeck/src/coherence/inherent_impls.rs
Original file line number Diff line number Diff line change
@@ -150,6 +150,19 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Not })
if matches!(inner.kind(), ty::Str) =>
{
self.check_primitive_impl(
item.def_id,
lang_items.const_str_ptr_impl(),
None,
"const_str_ptr",
"*const str",
item.span,
assoc_items,
);
}
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Mut })
if matches!(inner.kind(), ty::Slice(_)) =>
{
@@ -163,6 +176,19 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Mut })
if matches!(inner.kind(), ty::Str) =>
{
self.check_primitive_impl(
item.def_id,
lang_items.mut_str_ptr_impl(),
None,
"mut_str_ptr",
"*mut str",
item.span,
assoc_items,
);
}
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => {
self.check_primitive_impl(
item.def_id,