Skip to content

Commit 80e2a78

Browse files
authored
Rollup merge of #124957 - compiler-errors:builtin-deref, r=michaelwoerister
Make `Ty::builtin_deref` just return a `Ty` Nowhere in the compiler are we using the mutability part of the `TyAndMut` that we used to return.
2 parents 617c3f6 + 0a67bf1 commit 80e2a78

File tree

8 files changed

+13
-20
lines changed

8 files changed

+13
-20
lines changed

src/base.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,8 @@ fn codegen_stmt<'tcx>(
670670
let to_ty = fx.monomorphize(to_ty);
671671

672672
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
673-
ty.builtin_deref(true).is_some_and(
674-
|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| {
675-
has_ptr_meta(fx.tcx, pointee_ty)
676-
},
677-
)
673+
ty.builtin_deref(true)
674+
.is_some_and(|pointee_ty| has_ptr_meta(fx.tcx, pointee_ty))
678675
}
679676

680677
if is_fat_ptr(fx, from_ty) {

src/intrinsics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
586586
intrinsic_args!(fx, args => (base, offset); intrinsic);
587587
let offset = offset.load_scalar(fx);
588588

589-
let pointee_ty = base.layout().ty.builtin_deref(true).unwrap().ty;
589+
let pointee_ty = base.layout().ty.builtin_deref(true).unwrap();
590590
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
591591
let ptr_diff = if pointee_size != 1 {
592592
fx.bcx.ins().imul_imm(offset, pointee_size as i64)
@@ -610,7 +610,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
610610
let val = val.load_scalar(fx);
611611
let count = count.load_scalar(fx);
612612

613-
let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap().ty;
613+
let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap();
614614
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
615615
let count = if pointee_size != 1 {
616616
fx.bcx.ins().imul_imm(count, pointee_size as i64)
@@ -715,7 +715,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
715715

716716
// Cranelift treats loads as volatile by default
717717
// FIXME correctly handle unaligned_volatile_load
718-
let inner_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
718+
let inner_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap());
719719
let val = CValue::by_ref(Pointer::new(ptr.load_scalar(fx)), inner_layout);
720720
ret.write_cvalue(fx, val);
721721
}

src/intrinsics/simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
974974
intrinsic_args!(fx, args => (ptr, offset); intrinsic);
975975

976976
let (lane_count, ptr_lane_ty) = ptr.layout().ty.simd_size_and_type(fx.tcx);
977-
let pointee_ty = ptr_lane_ty.builtin_deref(true).unwrap().ty;
977+
let pointee_ty = ptr_lane_ty.builtin_deref(true).unwrap();
978978
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
979979
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
980980
let ret_lane_layout = fx.layout_of(ret_lane_ty);

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mod prelude {
9595
pub(crate) use rustc_middle::mir::{self, *};
9696
pub(crate) use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
9797
pub(crate) use rustc_middle::ty::{
98-
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut, UintTy,
98+
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, UintTy,
9999
};
100100
pub(crate) use rustc_span::Span;
101101
pub(crate) use rustc_target::abi::{Abi, FieldIdx, Scalar, Size, VariantIdx, FIRST_VARIANT};

src/num.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,8 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
388388
in_lhs: CValue<'tcx>,
389389
in_rhs: CValue<'tcx>,
390390
) -> CValue<'tcx> {
391-
let is_thin_ptr = in_lhs
392-
.layout()
393-
.ty
394-
.builtin_deref(true)
395-
.map(|TypeAndMut { ty, mutbl: _ }| !has_ptr_meta(fx.tcx, ty))
396-
.unwrap_or(true);
391+
let is_thin_ptr =
392+
in_lhs.layout().ty.builtin_deref(true).map(|ty| !has_ptr_meta(fx.tcx, ty)).unwrap_or(true);
397393

398394
if is_thin_ptr {
399395
match bin_op {
@@ -404,7 +400,7 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
404400
codegen_compare_bin_op(fx, bin_op, false, lhs, rhs)
405401
}
406402
BinOp::Offset => {
407-
let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap().ty;
403+
let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap();
408404
let (base, offset) = (in_lhs, in_rhs.load_scalar(fx));
409405
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
410406
let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);

src/unsize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub(crate) fn coerce_unsized_into<'tcx>(
127127
let dst_ty = dst.layout().ty;
128128
let mut coerce_ptr = || {
129129
let (base, info) =
130-
if fx.layout_of(src.layout().ty.builtin_deref(true).unwrap().ty).is_unsized() {
130+
if fx.layout_of(src.layout().ty.builtin_deref(true).unwrap()).is_unsized() {
131131
let (old_base, old_info) = src.load_scalar_pair(fx);
132132
unsize_ptr(fx, old_base, src.layout(), dst.layout(), Some(old_info))
133133
} else {

src/value_and_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ impl<'tcx> CPlace<'tcx> {
819819
}
820820

821821
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CPlace<'tcx> {
822-
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap().ty);
822+
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap());
823823
if has_ptr_meta(fx.tcx, inner_layout.ty) {
824824
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
825825
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)

src/vtable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
5959

6060
if let ty::Ref(_, ty, _) = arg.layout().ty.kind() {
6161
if ty.is_dyn_star() {
62-
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap().ty);
62+
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap());
6363
let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout);
6464
let ptr = dyn_star.place_field(fx, FieldIdx::ZERO).to_ptr();
6565
let vtable =

0 commit comments

Comments
 (0)