diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 7e2f3e62589f..01479180dd3e 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -2787,7 +2787,7 @@ fn can_use_as_ref(&self, expr: &hir::Expr<'_>) -> Option<(Vec<(Span, String)>, & return None; }; - let self_ty = self.typeck_results.borrow().expr_ty(receiver); + let self_ty = self.typeck_results.borrow().expr_ty_opt(receiver)?; let name = method_path.ident.name; let is_as_ref_able = match self_ty.peel_refs().kind() { ty::Adt(def, _) => {