From c7e140b0535b75f1ccfbab733cffb0b95462f852 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 16 Sep 2025 14:56:35 +0200 Subject: [PATCH] remove unnecessary `structurally_resolve_type` --- compiler/rustc_hir_typeck/src/method/confirm.rs | 3 +-- compiler/rustc_hir_typeck/src/place_op.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index a23910a2006c9..9f7b091d4f590 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -172,7 +172,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // Commit the autoderefs by calling `autoderef` again, but this // time writing the results into the various typeck results. let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty); - let Some((ty, n)) = autoderef.nth(pick.autoderefs) else { + let Some((mut target, n)) = autoderef.nth(pick.autoderefs) else { return Ty::new_error_with_message( self.tcx, DUMMY_SP, @@ -182,7 +182,6 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { assert_eq!(n, pick.autoderefs); let mut adjustments = self.adjust_steps(&autoderef); - let mut target = self.structurally_resolve_type(autoderef.span(), ty); match pick.autoref_or_ptr_adjustment { Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => { diff --git a/compiler/rustc_hir_typeck/src/place_op.rs b/compiler/rustc_hir_typeck/src/place_op.rs index 1125e98408045..1fa08c2aed752 100644 --- a/compiler/rustc_hir_typeck/src/place_op.rs +++ b/compiler/rustc_hir_typeck/src/place_op.rs @@ -67,12 +67,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { result } - fn negative_index( + fn negative_index_err( &self, ty: Ty<'tcx>, span: Span, base_expr: &hir::Expr<'_>, - ) -> Option<(Ty<'tcx>, Ty<'tcx>)> { + ) -> (Ty<'tcx>, Ty<'tcx>) { let ty = self.resolve_vars_if_possible(ty); let mut err = self.dcx().struct_span_err( span, @@ -92,8 +92,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Applicability::MachineApplicable, ); } - let reported = err.emit(); - Some((Ty::new_error(self.tcx, reported), Ty::new_error(self.tcx, reported))) + let guar = err.emit(); + (Ty::new_error(self.tcx, guar), Ty::new_error(self.tcx, guar)) } /// To type-check `base_expr[index_expr]`, we progressively autoderef @@ -109,7 +109,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { index_ty: Ty<'tcx>, index_expr: &hir::Expr<'_>, ) -> Option<(/*index type*/ Ty<'tcx>, /*element type*/ Ty<'tcx>)> { - let adjusted_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty()); + let adjusted_ty = autoderef.final_ty(); debug!( "try_index_step(expr={:?}, base_expr={:?}, adjusted_ty={:?}, \ index_ty={:?})", @@ -126,10 +126,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { match adjusted_ty.kind() { ty::Adt(def, _) if self.tcx.is_diagnostic_item(sym::Vec, def.did()) => { - return self.negative_index(adjusted_ty, index_expr.span, base_expr); + return Some(self.negative_index_err(adjusted_ty, index_expr.span, base_expr)); } ty::Slice(_) | ty::Array(_, _) => { - return self.negative_index(adjusted_ty, index_expr.span, base_expr); + return Some(self.negative_index_err(adjusted_ty, index_expr.span, base_expr)); } _ => {} }