Rename try_coerce to coerce

This commit is contained in:
Michael Goulet 2023-08-15 02:27:13 +00:00
parent 822caa8b80
commit 406b0e2935
4 changed files with 11 additions and 12 deletions

View File

@ -744,7 +744,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
ty::FnDef(..) => { ty::FnDef(..) => {
// Attempt a coercion to a fn pointer type. // Attempt a coercion to a fn pointer type.
let f = fcx.normalize(self.expr_span, self.expr_ty.fn_sig(fcx.tcx)); let f = fcx.normalize(self.expr_span, self.expr_ty.fn_sig(fcx.tcx));
let res = fcx.try_coerce( let res = fcx.coerce(
self.expr, self.expr,
self.expr_ty, self.expr_ty,
Ty::new_fn_ptr(fcx.tcx, f), Ty::new_fn_ptr(fcx.tcx, f),
@ -844,7 +844,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
(_, DynStar) => { (_, DynStar) => {
if fcx.tcx.features().dyn_star { if fcx.tcx.features().dyn_star {
bug!("should be handled by `try_coerce`") bug!("should be handled by `coerce`")
} else { } else {
Err(CastError::IllegalCast) Err(CastError::IllegalCast)
} }
@ -940,7 +940,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
// Coerce to a raw pointer so that we generate AddressOf in MIR. // Coerce to a raw pointer so that we generate AddressOf in MIR.
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr); let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr);
fcx.try_coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None) fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
bug!( bug!(
"could not cast from reference to array to pointer to array ({:?} to {:?})", "could not cast from reference to array to pointer to array ({:?} to {:?})",
@ -976,7 +976,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
} }
fn try_coercion_cast(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<(), ty::error::TypeError<'tcx>> { fn try_coercion_cast(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<(), ty::error::TypeError<'tcx>> {
match fcx.try_coerce(self.expr, self.expr_ty, self.cast_ty, AllowTwoPhase::No, None) { match fcx.coerce(self.expr, self.expr_ty, self.cast_ty, AllowTwoPhase::No, None) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(err) => Err(err), Err(err) => Err(err),
} }

View File

@ -1005,7 +1005,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// adjusted type of the expression, if successful. /// adjusted type of the expression, if successful.
/// Adjustments are only recorded if the coercion succeeded. /// Adjustments are only recorded if the coercion succeeded.
/// The expressions *must not* have any preexisting adjustments. /// The expressions *must not* have any preexisting adjustments.
pub fn try_coerce( pub fn coerce(
&self, &self,
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
expr_ty: Ty<'tcx>, expr_ty: Ty<'tcx>,
@ -1036,7 +1036,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}) })
} }
/// Same as `try_coerce()`, but without side-effects. /// Same as `coerce()`, but without side-effects.
/// ///
/// Returns false if the coercion creates any obligations that result in /// Returns false if the coercion creates any obligations that result in
/// errors. /// errors.
@ -1494,7 +1494,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
// Special-case the first expression we are coercing. // Special-case the first expression we are coercing.
// To be honest, I'm not entirely sure why we do this. // To be honest, I'm not entirely sure why we do this.
// We don't allow two-phase borrows, see comment in try_find_coercion_lub for why // We don't allow two-phase borrows, see comment in try_find_coercion_lub for why
fcx.try_coerce( fcx.coerce(
expression, expression,
expression_ty, expression_ty,
self.expected_ty, self.expected_ty,

View File

@ -254,7 +254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>>) { ) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>>) {
let expected = self.resolve_vars_with_obligations(expected); let expected = self.resolve_vars_with_obligations(expected);
let e = match self.try_coerce(expr, checked_ty, expected, allow_two_phase, None) { let e = match self.coerce(expr, checked_ty, expected, allow_two_phase, None) {
Ok(ty) => return (ty, None), Ok(ty) => return (ty, None),
Err(e) => e, Err(e) => e,
}; };
@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
let Some(arg_ty) = self.node_ty_opt(arg_expr.hir_id) else { continue; }; let Some(arg_ty) = self.node_ty_opt(arg_expr.hir_id) else { continue; };
let arg_ty = arg_ty.fold_with(&mut fudger); let arg_ty = arg_ty.fold_with(&mut fudger);
let _ = self.try_coerce( let _ = self.coerce(
arg_expr, arg_expr,
arg_ty, arg_ty,
*expected_arg_ty, *expected_arg_ty,

View File

@ -260,9 +260,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// fulfillment error to be more accurate. // fulfillment error to be more accurate.
let coerced_ty = self.resolve_vars_with_obligations(coerced_ty); let coerced_ty = self.resolve_vars_with_obligations(coerced_ty);
let coerce_error = self let coerce_error =
.try_coerce(provided_arg, checked_ty, coerced_ty, AllowTwoPhase::Yes, None) self.coerce(provided_arg, checked_ty, coerced_ty, AllowTwoPhase::Yes, None).err();
.err();
if coerce_error.is_some() { if coerce_error.is_some() {
return Compatibility::Incompatible(coerce_error); return Compatibility::Incompatible(coerce_error);