Skip to content

Commit 9a9ec90

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 aa68901 + d50c2b0 commit 9a9ec90

File tree

43 files changed

+92
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+92
-116
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1483,10 +1483,9 @@ fn suggest_ampmut<'tcx>(
14831483
} else {
14841484
// otherwise, suggest that the user annotates the binding; we provide the
14851485
// type of the local.
1486-
let ty_mut = decl_ty.builtin_deref(true).unwrap();
1487-
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
1486+
let ty = decl_ty.builtin_deref(true).unwrap();
14881487

1489-
(false, span, format!("{}mut {}", if decl_ty.is_ref() { "&" } else { "*" }, ty_mut.ty))
1488+
(false, span, format!("{}mut {}", if decl_ty.is_ref() { "&" } else { "*" }, ty))
14901489
}
14911490
}
14921491

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
400400
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
401401
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
402402
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
403-
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap().ty;
403+
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
404404

405405
if let Err(terr) = self.cx.eq_types(
406406
literal_ty,
@@ -637,7 +637,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
637637
match pi {
638638
ProjectionElem::Deref => {
639639
let deref_ty = base_ty.builtin_deref(true);
640-
PlaceTy::from_ty(deref_ty.map(|t| t.ty).unwrap_or_else(|| {
640+
PlaceTy::from_ty(deref_ty.unwrap_or_else(|| {
641641
span_mirbug_and_err!(self, place, "deref of non-pointer {:?}", base_ty)
642642
}))
643643
}

compiler/rustc_codegen_cranelift/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) {

compiler/rustc_codegen_cranelift/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
}

compiler/rustc_codegen_cranelift/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);

compiler/rustc_codegen_cranelift/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};

compiler/rustc_codegen_cranelift/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);

compiler/rustc_codegen_cranelift/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 {

compiler/rustc_codegen_cranelift/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)

compiler/rustc_codegen_cranelift/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 =

compiler/rustc_codegen_llvm/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
583583
let element_type_index = unsafe { llvm::LLVMRustGetElementTypeArgIndex(callsite) };
584584
if element_type_index >= 0 {
585585
let arg_ty = self.args[element_type_index as usize].layout.ty;
586-
let pointee_ty = arg_ty.builtin_deref(true).expect("Must be pointer argument").ty;
586+
let pointee_ty = arg_ty.builtin_deref(true).expect("Must be pointer argument");
587587
let element_type_attr = unsafe {
588588
llvm::LLVMRustCreateElementTypeAttr(bx.llcx, bx.layout_of(pointee_ty).llvm_type(bx))
589589
};

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
23872387
let pointee = in_elem.builtin_deref(true).unwrap_or_else(|| {
23882388
span_bug!(span, "must be called with a vector of pointer types as first argument")
23892389
});
2390-
let layout = bx.layout_of(pointee.ty);
2390+
let layout = bx.layout_of(pointee);
23912391
let ptrs = args[0].immediate();
23922392
// The second argument must be a ptr-sized integer.
23932393
// (We don't care about the signedness, this is wrapping anyway.)

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10601060

10611061
// Make sure that we've actually unwrapped the rcvr down
10621062
// to a pointer or ref to `dyn* Trait`.
1063-
if !op.layout.ty.builtin_deref(true).unwrap().ty.is_dyn_star() {
1063+
if !op.layout.ty.builtin_deref(true).unwrap().is_dyn_star() {
10641064
span_bug!(span, "can't codegen a virtual call on {:#?}", op);
10651065
}
10661066
let place = op.deref(bx.cx());

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> DebugInfoOffsetLocation<'tcx, Bx>
120120
{
121121
fn deref(&self, bx: &mut Bx) -> Self {
122122
bx.cx().layout_of(
123-
self.ty.builtin_deref(true).unwrap_or_else(|| bug!("cannot deref `{}`", self.ty)).ty,
123+
self.ty.builtin_deref(true).unwrap_or_else(|| bug!("cannot deref `{}`", self.ty)),
124124
)
125125
}
126126

compiler/rustc_codegen_ssa/src/mir/operand.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
215215
.layout
216216
.ty
217217
.builtin_deref(true)
218-
.unwrap_or_else(|| bug!("deref of non-pointer {:?}", self))
219-
.ty;
218+
.unwrap_or_else(|| bug!("deref of non-pointer {:?}", self));
220219

221220
let (llptr, llextra) = match self.val {
222221
OperandValue::Immediate(llptr) => (llptr, None),
@@ -455,8 +454,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
455454
.layout
456455
.ty
457456
.builtin_deref(true)
458-
.unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest))
459-
.ty;
457+
.unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest));
460458

461459
let OperandValue::Ref(PlaceValue { llval: llptr, llextra: Some(llextra), .. }) = self
462460
else {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
868868
mir::BinOp::Offset => {
869869
let pointee_type = input_ty
870870
.builtin_deref(true)
871-
.unwrap_or_else(|| bug!("deref of non-pointer {:?}", input_ty))
872-
.ty;
871+
.unwrap_or_else(|| bug!("deref of non-pointer {:?}", input_ty));
873872
let pointee_layout = bx.cx().layout_of(pointee_type);
874873
if pointee_layout.is_zst() {
875874
// `Offset` works in terms of the size of pointee,

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub(super) fn op_to_const<'tcx>(
222222
// This codepath solely exists for `valtree_to_const_value` to not need to generate
223223
// a `ConstValue::Indirect` for wide references, so it is tightly restricted to just
224224
// that case.
225-
let pointee_ty = imm.layout.ty.builtin_deref(false).unwrap().ty; // `false` = no raw ptrs
225+
let pointee_ty = imm.layout.ty.builtin_deref(false).unwrap(); // `false` = no raw ptrs
226226
debug_assert!(
227227
matches!(
228228
ecx.tcx.struct_tail_without_normalization(pointee_ty).kind(),

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
605605
nonoverlapping: bool,
606606
) -> InterpResult<'tcx> {
607607
let count = self.read_target_usize(count)?;
608-
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
608+
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap())?;
609609
let (size, align) = (layout.size, layout.align.abi);
610610
// `checked_mul` enforces a too small bound (the correct one would probably be target_isize_max),
611611
// but no actual allocation can be big enough for the difference to be noticeable.
@@ -649,7 +649,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
649649
byte: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,
650650
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,
651651
) -> InterpResult<'tcx> {
652-
let layout = self.layout_of(dst.layout.ty.builtin_deref(true).unwrap().ty)?;
652+
let layout = self.layout_of(dst.layout.ty.builtin_deref(true).unwrap())?;
653653

654654
let dst = self.read_pointer(dst)?;
655655
let byte = self.read_scalar(byte)?.to_u8()?;
@@ -688,7 +688,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
688688
lhs: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,
689689
rhs: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,
690690
) -> InterpResult<'tcx, Scalar<M::Provenance>> {
691-
let layout = self.layout_of(lhs.layout.ty.builtin_deref(true).unwrap().ty)?;
691+
let layout = self.layout_of(lhs.layout.ty.builtin_deref(true).unwrap())?;
692692
assert!(layout.is_sized());
693693

694694
let get_bytes = |this: &InterpCx<'mir, 'tcx, M>,

compiler/rustc_const_eval/src/interpret/operator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
357357
Offset => {
358358
let ptr = left.to_scalar().to_pointer(self)?;
359359
let offset_count = right.to_scalar().to_target_isize(self)?;
360-
let pointee_ty = left.layout.ty.builtin_deref(true).unwrap().ty;
360+
let pointee_ty = left.layout.ty.builtin_deref(true).unwrap();
361361

362362
// We cannot overflow i64 as a type's size must be <= isize::MAX.
363363
let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();

compiler/rustc_const_eval/src/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ where
415415
val: &ImmTy<'tcx, M::Provenance>,
416416
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
417417
let pointee_type =
418-
val.layout.ty.builtin_deref(true).expect("`ref_to_mplace` called on non-ptr type").ty;
418+
val.layout.ty.builtin_deref(true).expect("`ref_to_mplace` called on non-ptr type");
419419
let layout = self.layout_of(pointee_type)?;
420420
let (ptr, meta) = val.to_scalar_and_meta();
421421

compiler/rustc_const_eval/src/transform/validate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
12911291
)) => {
12921292
let src_ty = src.ty(&self.body.local_decls, self.tcx);
12931293
let op_src_ty = if let Some(src_deref) = src_ty.builtin_deref(true) {
1294-
src_deref.ty
1294+
src_deref
12951295
} else {
12961296
self.fail(
12971297
location,
@@ -1301,7 +1301,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
13011301
};
13021302
let dst_ty = dst.ty(&self.body.local_decls, self.tcx);
13031303
let op_dst_ty = if let Some(dst_deref) = dst_ty.builtin_deref(true) {
1304-
dst_deref.ty
1304+
dst_deref
13051305
} else {
13061306
self.fail(
13071307
location,

compiler/rustc_const_eval/src/util/check_validity_requirement.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn might_permit_raw_init_lax<'tcx>(
115115

116116
// Special magic check for references and boxes (i.e., special pointer types).
117117
if let Some(pointee) = this.ty.builtin_deref(false) {
118-
let pointee = cx.layout_of(pointee.ty)?;
118+
let pointee = cx.layout_of(pointee)?;
119119
// We need to ensure that the LLVM attributes `aligned` and `dereferenceable(size)` are satisfied.
120120
if pointee.align.abi.bytes() > 1 {
121121
// 0x01-filling is not aligned.

compiler/rustc_hir_analysis/src/autoderef.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,27 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
6868
}
6969

7070
// Otherwise, deref if type is derefable:
71-
let (kind, new_ty) = if let Some(ty::TypeAndMut { ty, .. }) =
72-
self.state.cur_ty.builtin_deref(self.include_raw_pointers)
73-
{
74-
debug_assert_eq!(ty, self.infcx.resolve_vars_if_possible(ty));
75-
// NOTE: we may still need to normalize the built-in deref in case
76-
// we have some type like `&<Ty as Trait>::Assoc`, since users of
77-
// autoderef expect this type to have been structurally normalized.
78-
if self.infcx.next_trait_solver()
79-
&& let ty::Alias(..) = ty.kind()
80-
{
81-
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;
82-
self.state.obligations.extend(obligations);
83-
(AutoderefKind::Builtin, normalized_ty)
71+
let (kind, new_ty) =
72+
if let Some(ty) = self.state.cur_ty.builtin_deref(self.include_raw_pointers) {
73+
debug_assert_eq!(ty, self.infcx.resolve_vars_if_possible(ty));
74+
// NOTE: we may still need to normalize the built-in deref in case
75+
// we have some type like `&<Ty as Trait>::Assoc`, since users of
76+
// autoderef expect this type to have been structurally normalized.
77+
if self.infcx.next_trait_solver()
78+
&& let ty::Alias(..) = ty.kind()
79+
{
80+
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;
81+
self.state.obligations.extend(obligations);
82+
(AutoderefKind::Builtin, normalized_ty)
83+
} else {
84+
(AutoderefKind::Builtin, ty)
85+
}
86+
} else if let Some(ty) = self.overloaded_deref_ty(self.state.cur_ty) {
87+
// The overloaded deref check already normalizes the pointee type.
88+
(AutoderefKind::Overloaded, ty)
8489
} else {
85-
(AutoderefKind::Builtin, ty)
86-
}
87-
} else if let Some(ty) = self.overloaded_deref_ty(self.state.cur_ty) {
88-
// The overloaded deref check already normalizes the pointee type.
89-
(AutoderefKind::Overloaded, ty)
90-
} else {
91-
return None;
92-
};
90+
return None;
91+
};
9392

9493
self.state.steps.push((self.state.cur_ty, kind));
9594
debug!(

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624624
/// returns a type of `&T`, but the actual type we assign to the
625625
/// *expression* is `T`. So this function just peels off the return
626626
/// type by one layer to yield `T`.
627-
pub(crate) fn make_overloaded_place_return_type(
628-
&self,
629-
method: MethodCallee<'tcx>,
630-
) -> ty::TypeAndMut<'tcx> {
627+
pub(crate) fn make_overloaded_place_return_type(&self, method: MethodCallee<'tcx>) -> Ty<'tcx> {
631628
// extract method return type, which will be &T;
632629
let ret_ty = method.sig.output();
633630

compiler/rustc_hir_typeck/src/mem_categorization.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
207207
// but what we want here is the type of the underlying value being borrowed.
208208
// So peel off one-level, turning the &T into T.
209209
match base_ty.builtin_deref(false) {
210-
Some(t) => Ok(t.ty),
210+
Some(ty) => Ok(ty),
211211
None => {
212212
debug!("By-ref binding of non-derefable type");
213213
Err(())
@@ -485,7 +485,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
485485
) -> McResult<PlaceWithHirId<'tcx>> {
486486
let base_curr_ty = base_place.place.ty();
487487
let deref_ty = match base_curr_ty.builtin_deref(true) {
488-
Some(mt) => mt.ty,
488+
Some(pointee_ty) => pointee_ty,
489489
None => {
490490
debug!("explicit deref of non-derefable type: {:?}", base_curr_ty);
491491
return Err(());

0 commit comments

Comments
 (0)