1
Fork 0

Extend the renaming to coerce_unsafe_ptr

This commit is contained in:
Bastian Kersting 2025-01-24 14:58:33 +00:00
parent f842ee8245
commit 432ff5e559
8 changed files with 16 additions and 16 deletions

View file

@ -900,8 +900,8 @@ fn codegen_stmt<'tcx>(
}; };
let data = codegen_operand(fx, data); let data = codegen_operand(fx, data);
let meta = codegen_operand(fx, meta); let meta = codegen_operand(fx, meta);
assert!(data.layout().ty.is_unsafe_ptr()); assert!(data.layout().ty.is_raw_ptr());
assert!(layout.ty.is_unsafe_ptr()); assert!(layout.ty.is_raw_ptr());
let ptr_val = if meta.layout().is_zst() { let ptr_val = if meta.layout().is_zst() {
data.cast_pointer_to(layout) data.cast_pointer_to(layout)
} else { } else {

View file

@ -48,7 +48,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
) -> (Pointer, Value) { ) -> (Pointer, Value) {
let (ptr, vtable) = 'block: { let (ptr, vtable) = 'block: {
if let BackendRepr::Scalar(_) = arg.layout().backend_repr { if let BackendRepr::Scalar(_) = arg.layout().backend_repr {
while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() { while !arg.layout().ty.is_raw_ptr() && !arg.layout().ty.is_ref() {
let (idx, _) = arg let (idx, _) = arg
.layout() .layout()
.non_1zst_field(fx) .non_1zst_field(fx)

View file

@ -219,7 +219,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// or pin-ergonomics. // or pin-ergonomics.
match *b.kind() { match *b.kind() {
ty::RawPtr(_, b_mutbl) => { ty::RawPtr(_, b_mutbl) => {
return self.coerce_unsafe_ptr(a, b, b_mutbl); return self.coerce_raw_ptr(a, b, b_mutbl);
} }
ty::Ref(r_b, _, mutbl_b) => { ty::Ref(r_b, _, mutbl_b) => {
return self.coerce_borrowed_pointer(a, b, r_b, mutbl_b); return self.coerce_borrowed_pointer(a, b, r_b, mutbl_b);
@ -1017,13 +1017,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
} }
} }
fn coerce_unsafe_ptr( fn coerce_raw_ptr(
&self, &self,
a: Ty<'tcx>, a: Ty<'tcx>,
b: Ty<'tcx>, b: Ty<'tcx>,
mutbl_b: hir::Mutability, mutbl_b: hir::Mutability,
) -> CoerceResult<'tcx> { ) -> CoerceResult<'tcx> {
debug!("coerce_unsafe_ptr(a={:?}, b={:?})", a, b); debug!("coerce_raw_ptr(a={:?}, b={:?})", a, b);
let (is_ref, mt_a) = match *a.kind() { let (is_ref, mt_a) = match *a.kind() {
ty::Ref(_, ty, mutbl) => (true, ty::TypeAndMut { ty, mutbl }), ty::Ref(_, ty, mutbl) => (true, ty::TypeAndMut { ty, mutbl }),
@ -1033,21 +1033,21 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
coerce_mutbls(mt_a.mutbl, mutbl_b)?; coerce_mutbls(mt_a.mutbl, mutbl_b)?;
// Check that the types which they point at are compatible. // Check that the types which they point at are compatible.
let a_unsafe = Ty::new_ptr(self.tcx, mt_a.ty, mutbl_b); let a_raw = Ty::new_ptr(self.tcx, mt_a.ty, mutbl_b);
// Although references and unsafe ptrs have the same // Although references and raw ptrs have the same
// representation, we still register an Adjust::DerefRef so that // representation, we still register an Adjust::DerefRef so that
// regionck knows that the region for `a` must be valid here. // regionck knows that the region for `a` must be valid here.
if is_ref { if is_ref {
self.unify_and(a_unsafe, b, |target| { self.unify_and(a_raw, b, |target| {
vec![ vec![
Adjustment { kind: Adjust::Deref(None), target: mt_a.ty }, Adjustment { kind: Adjust::Deref(None), target: mt_a.ty },
Adjustment { kind: Adjust::Borrow(AutoBorrow::RawPtr(mutbl_b)), target }, Adjustment { kind: Adjust::Borrow(AutoBorrow::RawPtr(mutbl_b)), target },
] ]
}) })
} else if mt_a.mutbl != mutbl_b { } else if mt_a.mutbl != mutbl_b {
self.unify_and(a_unsafe, b, simple(Adjust::Pointer(PointerCoercion::MutToConstPointer))) self.unify_and(a_raw, b, simple(Adjust::Pointer(PointerCoercion::MutToConstPointer)))
} else { } else {
self.unify_and(a_unsafe, b, identity) self.unify_and(a_raw, b, identity)
} }
} }
} }

View file

@ -2103,7 +2103,7 @@ fn restrict_precision_for_unsafe(
for (i, proj) in place.projections.iter().enumerate() { for (i, proj) in place.projections.iter().enumerate() {
if proj.ty.is_raw_ptr() { if proj.ty.is_raw_ptr() {
// Don't apply any projections on top of an unsafe ptr. // Don't apply any projections on top of a raw ptr.
truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i + 1); truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i + 1);
break; break;
} }

View file

@ -1394,7 +1394,7 @@ impl<'tcx> Ty<'tcx> {
/// Returns the type and mutability of `*ty`. /// Returns the type and mutability of `*ty`.
/// ///
/// The parameter `explicit` indicates if this is an *explicit* dereference. /// The parameter `explicit` indicates if this is an *explicit* dereference.
/// Some types -- notably unsafe ptrs -- can only be dereferenced explicitly. /// Some types -- notably raw ptrs -- can only be dereferenced explicitly.
pub fn builtin_deref(self, explicit: bool) -> Option<Ty<'tcx>> { pub fn builtin_deref(self, explicit: bool) -> Option<Ty<'tcx>> {
match *self.kind() { match *self.kind() {
_ if let Some(boxed) = self.boxed_ty() => Some(boxed), _ if let Some(boxed) = self.boxed_ty() => Some(boxed),

View file

@ -489,7 +489,7 @@ impl TyKind {
/// Returns the type and mutability of `*ty` for builtin types. /// Returns the type and mutability of `*ty` for builtin types.
/// ///
/// The parameter `explicit` indicates if this is an *explicit* dereference. /// The parameter `explicit` indicates if this is an *explicit* dereference.
/// Some types -- notably unsafe ptrs -- can only be dereferenced explicitly. /// Some types -- notably raw ptrs -- can only be dereferenced explicitly.
pub fn builtin_deref(&self, explicit: bool) -> Option<TypeAndMut> { pub fn builtin_deref(&self, explicit: bool) -> Option<TypeAndMut> {
match self.rigid()? { match self.rigid()? {
RigidTy::Adt(def, args) if def.is_box() => { RigidTy::Adt(def, args) if def.is_box() => {

View file

@ -373,7 +373,7 @@ impl InferenceTable<'_> {
// Check that the types which they point at are compatible. // Check that the types which they point at are compatible.
let from_raw = TyKind::Raw(to_mt, from_inner.clone()).intern(Interner); let from_raw = TyKind::Raw(to_mt, from_inner.clone()).intern(Interner);
// Although references and unsafe ptrs have the same // Although references and raw ptrs have the same
// representation, we still register an Adjust::DerefRef so that // representation, we still register an Adjust::DerefRef so that
// regionck knows that the region for `a` must be valid here. // regionck knows that the region for `a` must be valid here.
if is_ref { if is_ref {

View file

@ -45,7 +45,7 @@ fn test<'a,T,U:Copy>(_: &'a isize) {
// mutable object types are not ok // mutable object types are not ok
assert_copy::<&'a mut (dyn Dummy + Send)>(); //~ ERROR : Copy` is not satisfied assert_copy::<&'a mut (dyn Dummy + Send)>(); //~ ERROR : Copy` is not satisfied
// unsafe ptrs are ok // raw ptrs are ok
assert_copy::<*const isize>(); assert_copy::<*const isize>();
assert_copy::<*const &'a mut isize>(); assert_copy::<*const &'a mut isize>();