Skip to content

Commit 33e8027

Browse files
committed
review comment
1 parent 65c17ae commit 33e8027

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
4040
use rustc_infer::infer::DefineOpaqueTypes;
4141
use rustc_infer::infer::InferOk;
4242
use rustc_infer::traits::query::NoSolution;
43-
use rustc_infer::traits::ObligationCause;
43+
use rustc_infer::traits::{ObligationCause, TraitEngineExt as _};
4444
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
4545
use rustc_middle::ty::error::{
4646
ExpectedFound,
@@ -59,8 +59,9 @@ use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
5959
use rustc_target::spec::abi::Abi::RustIntrinsic;
6060
use rustc_trait_selection::infer::InferCtxtExt;
6161
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
62-
use rustc_trait_selection::traits::ObligationCtxt;
63-
use rustc_trait_selection::traits::{self, ObligationCauseCode};
62+
use rustc_trait_selection::traits::{
63+
self, ObligationCauseCode, ObligationCtxt, TraitEngine, TraitEngineExt,
64+
};
6465

6566
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6667
pub fn check_expr_has_type_or_error(
@@ -3171,18 +3172,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31713172
// cause code.
31723173
if let hir::ExprKind::AddrOf(_, _, idx) = idx.kind {
31733174
let idx_t = self.typeck_results.borrow().expr_ty(idx);
3174-
if let Some((index_ty, _element_ty)) =
3175-
self.lookup_indexing(expr, base, base_t, idx, idx_t)
3176-
{
3177-
let (_ty, err) =
3178-
self.demand_coerce_diag(idx, idx_t, index_ty, None, AllowTwoPhase::No);
3179-
if let Some(err) = err {
3180-
err.cancel();
3181-
} else if self
3182-
.fulfillment_cx
3183-
.borrow_mut()
3184-
.select_where_possible(self)
3185-
.is_empty()
3175+
let mut autoderef = self.autoderef(base.span, base_t);
3176+
let mut result = None;
3177+
while result.is_none() && autoderef.next().is_some() {
3178+
result = self.try_index_step(expr, base, &autoderef, idx_t, idx);
3179+
}
3180+
let obligations = autoderef.into_obligations();
3181+
let mut fulfillment_cx = <dyn TraitEngine<'_>>::new(&self.infcx);
3182+
fulfillment_cx.register_predicate_obligations(&self.infcx, obligations);
3183+
if let Some((index_ty, _element_ty)) = result {
3184+
if self.can_coerce(idx_t, index_ty)
3185+
&& fulfillment_cx.select_where_possible(self).is_empty()
31863186
{
31873187
if let Some(pred) = error.obligation.predicate.to_opt_poly_trait_pred() {
31883188
error.obligation.cause =

compiler/rustc_hir_typeck/src/place_op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9898
/// supports builtin indexing or overloaded indexing.
9999
/// This loop implements one step in that search; the autoderef loop
100100
/// is implemented by `lookup_indexing`.
101-
fn try_index_step(
101+
pub(super) fn try_index_step(
102102
&self,
103103
expr: &hir::Expr<'_>,
104104
base_expr: &hir::Expr<'_>,

0 commit comments

Comments
 (0)