rustc: add lang items "const_slice_ptr" and "mut_slice_ptr"

Add lang items for methods on raw slices.
This commit is contained in:
Matthias Schiffer 2020-04-13 20:52:06 +02:00
parent ba72b15666
commit 10ae85f527
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
3 changed files with 35 additions and 4 deletions

View File

@ -135,6 +135,8 @@ language_item_table! {
SliceU8AllocImplItem, "slice_u8_alloc", slice_u8_alloc_impl, Target::Impl;
ConstPtrImplItem, "const_ptr", const_ptr_impl, Target::Impl;
MutPtrImplItem, "mut_ptr", mut_ptr_impl, Target::Impl;
ConstSlicePtrImplItem, "const_slice_ptr", const_slice_ptr_impl, Target::Impl;
MutSlicePtrImplItem, "mut_slice_ptr", mut_slice_ptr_impl, Target::Impl;
I8ImplItem, "i8", i8_impl, Target::Impl;
I16ImplItem, "i16", i16_impl, Target::Impl;
I32ImplItem, "i32", i32_impl, Target::Impl;

View File

@ -649,11 +649,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl }) => {
let lang_def_id = match mutbl {
hir::Mutability::Not => lang_items.const_ptr_impl(),
hir::Mutability::Mut => lang_items.mut_ptr_impl(),
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())
}
};
self.assemble_inherent_impl_for_primitive(lang_def_id);
self.assemble_inherent_impl_for_primitive(lang_def_id1);
self.assemble_inherent_impl_for_primitive(lang_def_id2);
}
ty::Int(i) => {
let lang_def_id = match i {

View File

@ -112,6 +112,30 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
item.span,
);
}
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Not })
if matches!(inner.kind, ty::Slice(_)) =>
{
self.check_primitive_impl(
def_id,
lang_items.const_slice_ptr_impl(),
None,
"const_slice_ptr",
"*const [T]",
item.span,
);
}
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Mut })
if matches!(inner.kind, ty::Slice(_)) =>
{
self.check_primitive_impl(
def_id,
lang_items.mut_slice_ptr_impl(),
None,
"mut_slice_ptr",
"*mut [T]",
item.span,
);
}
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => {
self.check_primitive_impl(
def_id,