Skip to content

Commit 6fd0e50

Browse files
committed
autoderef final ty is already resolved
1 parent 41f2b6b commit 6fd0e50

File tree

6 files changed

+10
-16
lines changed

6 files changed

+10
-16
lines changed

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
202202
Some((normalized_ty, ocx.into_pending_obligations()))
203203
}
204204

205-
/// Returns the final type we ended up with, which may be an inference
206-
/// variable (we will resolve it first, if we want).
207-
pub fn final_ty(&self, resolve: bool) -> Ty<'tcx> {
208-
if resolve {
209-
self.infcx.resolve_vars_if_possible(self.state.cur_ty)
210-
} else {
211-
self.state.cur_ty
212-
}
205+
/// Returns the final type we ended up with, which may be an unresolved
206+
/// inference variable.
207+
pub fn final_ty(&self) -> Ty<'tcx> {
208+
self.state.cur_ty
213209
}
214210

215211
pub fn step_count(&self) -> usize {

compiler/rustc_hir_typeck/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4242

4343
let mut obligations = PredicateObligations::new();
4444
let targets =
45-
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty(false)));
45+
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty()));
4646
let steps: Vec<_> = steps
4747
.iter()
4848
.map(|&(source, kind)| {

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8686
result = self.try_overloaded_call_step(call_expr, callee_expr, arg_exprs, &autoderef);
8787
}
8888

89-
match autoderef.final_ty(false).kind() {
89+
match autoderef.final_ty().kind() {
9090
ty::FnDef(def_id, _) => {
9191
let abi = self.tcx.fn_sig(def_id).skip_binder().skip_binder().abi;
9292
self.check_call_abi(abi, call_expr.span);
@@ -200,8 +200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200200
arg_exprs: &'tcx [hir::Expr<'tcx>],
201201
autoderef: &Autoderef<'a, 'tcx>,
202202
) -> Option<CallStep<'tcx>> {
203-
let adjusted_ty =
204-
self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false));
203+
let adjusted_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty());
205204

206205
// If the callee is a function pointer or a closure, then we're all set.
207206
match *adjusted_ty.kind() {

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29182918
// Emits an error if we deref an infer variable, like calling `.field` on a base type
29192919
// of `&_`. We can also use this to suppress unnecessary "missing field" errors that
29202920
// will follow ambiguity errors.
2921-
let final_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false));
2921+
let final_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty());
29222922
if let ty::Error(_) = final_ty.kind() {
29232923
return final_ty;
29242924
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ pub(crate) fn method_autoderef_steps<'tcx>(
629629
.collect();
630630
(steps, autoderef_via_deref.reached_recursion_limit())
631631
};
632-
let final_ty = autoderef_via_deref.final_ty(true);
632+
let final_ty = autoderef_via_deref.final_ty();
633633
let opt_bad_ty = match final_ty.kind() {
634634
ty::Infer(ty::TyVar(_)) | ty::Error(_) => Some(MethodAutoderefBadTy {
635635
reached_raw_pointer,

compiler/rustc_hir_typeck/src/place_op.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
109109
index_ty: Ty<'tcx>,
110110
index_expr: &hir::Expr<'_>,
111111
) -> Option<(/*index type*/ Ty<'tcx>, /*element type*/ Ty<'tcx>)> {
112-
let adjusted_ty =
113-
self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false));
112+
let adjusted_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty());
114113
debug!(
115114
"try_index_step(expr={:?}, base_expr={:?}, adjusted_ty={:?}, \
116115
index_ty={:?})",

0 commit comments

Comments
 (0)