Skip to content

Commit 10ae85f

Browse files
committed
rustc: add lang items "const_slice_ptr" and "mut_slice_ptr"
Add lang items for methods on raw slices.
1 parent ba72b15 commit 10ae85f

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/librustc_hir/lang_items.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ language_item_table! {
135135
SliceU8AllocImplItem, "slice_u8_alloc", slice_u8_alloc_impl, Target::Impl;
136136
ConstPtrImplItem, "const_ptr", const_ptr_impl, Target::Impl;
137137
MutPtrImplItem, "mut_ptr", mut_ptr_impl, Target::Impl;
138+
ConstSlicePtrImplItem, "const_slice_ptr", const_slice_ptr_impl, Target::Impl;
139+
MutSlicePtrImplItem, "mut_slice_ptr", mut_slice_ptr_impl, Target::Impl;
138140
I8ImplItem, "i8", i8_impl, Target::Impl;
139141
I16ImplItem, "i16", i16_impl, Target::Impl;
140142
I32ImplItem, "i32", i32_impl, Target::Impl;

src/librustc_typeck/check/method/probe.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
649649
}
650650
}
651651
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl }) => {
652-
let lang_def_id = match mutbl {
653-
hir::Mutability::Not => lang_items.const_ptr_impl(),
654-
hir::Mutability::Mut => lang_items.mut_ptr_impl(),
652+
let (lang_def_id1, lang_def_id2) = match mutbl {
653+
hir::Mutability::Not => {
654+
(lang_items.const_ptr_impl(), lang_items.const_slice_ptr_impl())
655+
}
656+
hir::Mutability::Mut => {
657+
(lang_items.mut_ptr_impl(), lang_items.mut_slice_ptr_impl())
658+
}
655659
};
656-
self.assemble_inherent_impl_for_primitive(lang_def_id);
660+
self.assemble_inherent_impl_for_primitive(lang_def_id1);
661+
self.assemble_inherent_impl_for_primitive(lang_def_id2);
657662
}
658663
ty::Int(i) => {
659664
let lang_def_id = match i {

src/librustc_typeck/coherence/inherent_impls.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
112112
item.span,
113113
);
114114
}
115+
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Not })
116+
if matches!(inner.kind, ty::Slice(_)) =>
117+
{
118+
self.check_primitive_impl(
119+
def_id,
120+
lang_items.const_slice_ptr_impl(),
121+
None,
122+
"const_slice_ptr",
123+
"*const [T]",
124+
item.span,
125+
);
126+
}
127+
ty::RawPtr(ty::TypeAndMut { ty: inner, mutbl: hir::Mutability::Mut })
128+
if matches!(inner.kind, ty::Slice(_)) =>
129+
{
130+
self.check_primitive_impl(
131+
def_id,
132+
lang_items.mut_slice_ptr_impl(),
133+
None,
134+
"mut_slice_ptr",
135+
"*mut [T]",
136+
item.span,
137+
);
138+
}
115139
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => {
116140
self.check_primitive_impl(
117141
def_id,

0 commit comments

Comments
 (0)