Skip to content

Commit 697768a

Browse files
committed
Simplify some unify_and calls
1 parent f20efc4 commit 697768a

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
191191
// we have no information about the source type. This will always
192192
// ultimately fall back to some form of subtyping.
193193
if a.is_ty_var() {
194-
return self.coerce_from_inference_variable(a, b, identity);
194+
return self.coerce_from_inference_variable(a, b);
195195
}
196196

197197
// Consider coercing the subtype to a DST
@@ -265,12 +265,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
265265
/// Coercing *from* an inference variable. In this case, we have no information
266266
/// about the source type, so we can't really do a true coercion and we always
267267
/// fall back to subtyping (`unify_and`).
268-
fn coerce_from_inference_variable(
269-
&self,
270-
a: Ty<'tcx>,
271-
b: Ty<'tcx>,
272-
make_adjustments: impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>>,
273-
) -> CoerceResult<'tcx> {
268+
fn coerce_from_inference_variable(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
274269
debug!("coerce_from_inference_variable(a={:?}, b={:?})", a, b);
275270
assert!(a.is_ty_var() && self.shallow_resolve(a) == a);
276271
assert!(self.shallow_resolve(b) == b);
@@ -298,12 +293,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
298293
"coerce_from_inference_variable: two inference variables, target_ty={:?}, obligations={:?}",
299294
target_ty, obligations
300295
);
301-
let adjustments = make_adjustments(target_ty);
302-
InferResult::Ok(InferOk { value: (adjustments, target_ty), obligations })
296+
success(vec![], target_ty, obligations)
303297
} else {
304298
// One unresolved type variable: just apply subtyping, we may be able
305299
// to do something useful.
306-
self.unify_and(a, b, make_adjustments)
300+
self.unify_and(a, b, identity)
307301
}
308302
}
309303

@@ -708,7 +702,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
708702
&& let ty::Dynamic(b_data, _, ty::DynStar) = b.kind()
709703
&& a_data.principal_def_id() == b_data.principal_def_id()
710704
{
711-
return self.unify_and(a, b, |_| vec![]);
705+
return self.unify_and(a, b, identity);
712706
}
713707

714708
// Check the obligations of the cast -- for example, when casting
@@ -808,9 +802,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
808802

809803
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we
810804
// add the adjustments.
811-
self.unify_and(a, b, |_inner_ty| {
812-
vec![Adjustment { kind: Adjust::ReborrowPin(mut_b), target: b }]
813-
})
805+
self.unify_and(a, b, simple(Adjust::ReborrowPin(mut_b)))
814806
}
815807

816808
fn coerce_from_safe_fn(

0 commit comments

Comments
 (0)