@@ -459,6 +459,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
459459 // If we encountered an `_` type or an error type during autoderef, this is
460460 // ambiguous.
461461 if let Some ( bad_ty) = & steps. opt_bad_ty {
462+ // Ended up encountering a type variable when doing autoderef,
463+ // but it may not be a type variable after processing obligations
464+ // in our local `FnCtxt`, so don't call `structurally_resolve_type`.
465+ let ty = & bad_ty. ty ;
466+ let ty = self
467+ . probe_instantiate_query_response ( span, & orig_values, ty)
468+ . unwrap_or_else ( |_| span_bug ! ( span, "instantiating {:?} failed?" , ty) ) ;
469+ let ty = self . resolve_vars_if_possible ( ty. value ) ;
470+
462471 if is_suggestion. 0 {
463472 // Ambiguity was encountered during a suggestion. There's really
464473 // not much use in suggesting methods in this case.
@@ -482,15 +491,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
482491 span,
483492 MissingTypeAnnot ,
484493 ) ;
494+ // If `ty` is an inference variable that was created by being adjusted from the never type,
495+ // We demand the type to be equal to the never type, so we can probe the never type for methods
496+ // (see https://github.com/rust-lang/rust/issues/143349)
497+ } else if let ty:: Infer ( ty:: TyVar ( ty_id) ) = * ty. kind ( )
498+ && let ty_id = self . root_var ( ty_id)
499+ && let root_ty = Ty :: new_var ( self . tcx , ty_id)
500+ && self
501+ . diverging_type_vars
502+ . borrow ( )
503+ . iter ( )
504+ . any ( |& candidate_id| self . root_var ( candidate_id) == ty_id)
505+ {
506+ self . demand_eqtype ( span, root_ty, self . tcx . types . never ) ;
485507 } else {
486- // Ended up encountering a type variable when doing autoderef,
487- // but it may not be a type variable after processing obligations
488- // in our local `FnCtxt`, so don't call `structurally_resolve_type`.
489- let ty = & bad_ty. ty ;
490- let ty = self
491- . probe_instantiate_query_response ( span, & orig_values, ty)
492- . unwrap_or_else ( |_| span_bug ! ( span, "instantiating {:?} failed?" , ty) ) ;
493- let ty = self . resolve_vars_if_possible ( ty. value ) ;
494508 let guar = match * ty. kind ( ) {
495509 _ if let Some ( guar) = self . tainted_by_errors ( ) => guar,
496510 ty:: Infer ( ty:: TyVar ( _) ) => {
0 commit comments