@@ -40,7 +40,7 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
40
40
use rustc_infer:: infer:: DefineOpaqueTypes ;
41
41
use rustc_infer:: infer:: InferOk ;
42
42
use rustc_infer:: traits:: query:: NoSolution ;
43
- use rustc_infer:: traits:: ObligationCause ;
43
+ use rustc_infer:: traits:: { ObligationCause , TraitEngineExt as _ } ;
44
44
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AllowTwoPhase } ;
45
45
use rustc_middle:: ty:: error:: {
46
46
ExpectedFound ,
@@ -59,8 +59,9 @@ use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
59
59
use rustc_target:: spec:: abi:: Abi :: RustIntrinsic ;
60
60
use rustc_trait_selection:: infer:: InferCtxtExt ;
61
61
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
+ } ;
64
65
65
66
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
66
67
pub fn check_expr_has_type_or_error (
@@ -3171,18 +3172,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3171
3172
// cause code.
3172
3173
if let hir:: ExprKind :: AddrOf ( _, _, idx) = idx. kind {
3173
3174
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 ( )
3186
3186
{
3187
3187
if let Some ( pred) = error. obligation . predicate . to_opt_poly_trait_pred ( ) {
3188
3188
error. obligation . cause =
0 commit comments