Skip to content

Commit 406b0e2

Browse files
Rename try_coerce to coerce
1 parent 822caa8 commit 406b0e2

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

compiler/rustc_hir_typeck/src/cast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
744744
ty::FnDef(..) => {
745745
// Attempt a coercion to a fn pointer type.
746746
let f = fcx.normalize(self.expr_span, self.expr_ty.fn_sig(fcx.tcx));
747-
let res = fcx.try_coerce(
747+
let res = fcx.coerce(
748748
self.expr,
749749
self.expr_ty,
750750
Ty::new_fn_ptr(fcx.tcx, f),
@@ -844,7 +844,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
844844

845845
(_, DynStar) => {
846846
if fcx.tcx.features().dyn_star {
847-
bug!("should be handled by `try_coerce`")
847+
bug!("should be handled by `coerce`")
848848
} else {
849849
Err(CastError::IllegalCast)
850850
}
@@ -940,7 +940,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
940940

941941
// Coerce to a raw pointer so that we generate AddressOf in MIR.
942942
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr);
943-
fcx.try_coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
943+
fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
944944
.unwrap_or_else(|_| {
945945
bug!(
946946
"could not cast from reference to array to pointer to array ({:?} to {:?})",
@@ -976,7 +976,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
976976
}
977977

978978
fn try_coercion_cast(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<(), ty::error::TypeError<'tcx>> {
979-
match fcx.try_coerce(self.expr, self.expr_ty, self.cast_ty, AllowTwoPhase::No, None) {
979+
match fcx.coerce(self.expr, self.expr_ty, self.cast_ty, AllowTwoPhase::No, None) {
980980
Ok(_) => Ok(()),
981981
Err(err) => Err(err),
982982
}

compiler/rustc_hir_typeck/src/coercion.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10051005
/// adjusted type of the expression, if successful.
10061006
/// Adjustments are only recorded if the coercion succeeded.
10071007
/// The expressions *must not* have any preexisting adjustments.
1008-
pub fn try_coerce(
1008+
pub fn coerce(
10091009
&self,
10101010
expr: &hir::Expr<'_>,
10111011
expr_ty: Ty<'tcx>,
@@ -1036,7 +1036,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10361036
})
10371037
}
10381038

1039-
/// Same as `try_coerce()`, but without side-effects.
1039+
/// Same as `coerce()`, but without side-effects.
10401040
///
10411041
/// Returns false if the coercion creates any obligations that result in
10421042
/// errors.
@@ -1494,7 +1494,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14941494
// Special-case the first expression we are coercing.
14951495
// To be honest, I'm not entirely sure why we do this.
14961496
// We don't allow two-phase borrows, see comment in try_find_coercion_lub for why
1497-
fcx.try_coerce(
1497+
fcx.coerce(
14981498
expression,
14991499
expression_ty,
15001500
self.expected_ty,

compiler/rustc_hir_typeck/src/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
254254
) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>>) {
255255
let expected = self.resolve_vars_with_obligations(expected);
256256

257-
let e = match self.try_coerce(expr, checked_ty, expected, allow_two_phase, None) {
257+
let e = match self.coerce(expr, checked_ty, expected, allow_two_phase, None) {
258258
Ok(ty) => return (ty, None),
259259
Err(e) => e,
260260
};
@@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
475475
{
476476
let Some(arg_ty) = self.node_ty_opt(arg_expr.hir_id) else { continue; };
477477
let arg_ty = arg_ty.fold_with(&mut fudger);
478-
let _ = self.try_coerce(
478+
let _ = self.coerce(
479479
arg_expr,
480480
arg_ty,
481481
*expected_arg_ty,

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
260260
// fulfillment error to be more accurate.
261261
let coerced_ty = self.resolve_vars_with_obligations(coerced_ty);
262262

263-
let coerce_error = self
264-
.try_coerce(provided_arg, checked_ty, coerced_ty, AllowTwoPhase::Yes, None)
265-
.err();
263+
let coerce_error =
264+
self.coerce(provided_arg, checked_ty, coerced_ty, AllowTwoPhase::Yes, None).err();
266265

267266
if coerce_error.is_some() {
268267
return Compatibility::Incompatible(coerce_error);

0 commit comments

Comments
 (0)