@@ -12,6 +12,7 @@ use rustc_hir::def::DefKind;
12
12
use rustc_hir_analysis:: autoderef:: { self , Autoderef } ;
13
13
use rustc_infer:: infer:: canonical:: OriginalQueryValues ;
14
14
use rustc_infer:: infer:: canonical:: { Canonical , QueryResponse } ;
15
+ use rustc_infer:: infer:: error_reporting:: TypeAnnotationNeeded :: E0282 ;
15
16
use rustc_infer:: infer:: DefineOpaqueTypes ;
16
17
use rustc_infer:: infer:: { self , InferOk , TyCtxtInferExt } ;
17
18
use rustc_middle:: middle:: stability;
@@ -448,15 +449,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
448
449
) ;
449
450
}
450
451
} else {
451
- // Encountered a real ambiguity, so abort the lookup. If `ty` is not
452
- // an `Err`, report the right " type annotations needed" error pointing
453
- // to it .
452
+ // Ended up encountering a type variable when doing autoderef,
453
+ // but it may not be a type variable after processing obligations
454
+ // in our local `FnCtxt`, so don't call `structurally_resolved_type` .
454
455
let ty = & bad_ty. ty ;
455
456
let ty = self
456
457
. probe_instantiate_query_response ( span, & orig_values, ty)
457
458
. unwrap_or_else ( |_| span_bug ! ( span, "instantiating {:?} failed?" , ty) ) ;
458
- let ty = self . structurally_resolved_type ( span, ty. value ) ;
459
- assert ! ( matches!( ty. kind( ) , ty:: Error ( _) ) ) ;
459
+ let ty = self . resolve_vars_if_possible ( ty. value ) ;
460
+ let guar = match * ty. kind ( ) {
461
+ ty:: Infer ( ty:: TyVar ( _) ) => self
462
+ . err_ctxt ( )
463
+ . emit_inference_failure_err ( self . body_id , span, ty. into ( ) , E0282 , true )
464
+ . emit ( ) ,
465
+ ty:: Error ( guar) => guar,
466
+ _ => bug ! ( "unexpected bad final type in method autoderef" ) ,
467
+ } ;
468
+ self . demand_eqtype ( span, ty, self . tcx . ty_error ( guar) ) ;
460
469
return Err ( MethodError :: NoMatch ( NoMatchData {
461
470
static_candidates : Vec :: new ( ) ,
462
471
unsatisfied_predicates : Vec :: new ( ) ,
0 commit comments