pub fn try_coerce(&self,
                      expr: &hir::Expr,
                      target: Ty<'tcx>)
                      -> RelateResult<'tcx, Ty<'tcx>> {
        let source = self.resolve_type_vars_with_obligations(self.expr_ty(expr));
        debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);

        let mut coerce = Coerce::new(self, TypeOrigin::ExprAssignable(expr.span));
        self.commit_if_ok(|_| {
            let (ty, adjustment) =
                apply(&mut coerce, &|| Some(expr), source, target)?;
            if !adjustment.is_identity() {
                debug!("Success, coerced with {:?}", adjustment);
                assert!(!self.tables.borrow().adjustments.contains_key(&expr.id));
                self.write_adjustment(expr.id, adjustment);
            }
            Ok(ty)
        })
    }
/// Attempt to coerce an expression to a type, and return the
/// adjusted type of the expression, if successful.
/// Adjustments are only recorded if the coercion succeeded.
/// The expressions *must not* have any pre-existing adjustments.
Attempt to coerce an expression to a type, and return the
adjusted type of the expression, if successful.
Adjustments are only recorded if the coercion succeeded.
The expressions *must not* have any pre-existing adjustments.
Attempt to coerce an expression to a type and return the adjusted type of the expression if successful . Adjustments are only recorded if the coercion succeeded . The expressions * must not * have any pre - existing adjustments .
pub fn try_coerce(&self,
                      expr: &hir::Expr,
                      target: Ty<'tcx>)
                      -> RelateResult<'tcx, Ty<'tcx>> {
        let source = self.resolve_type_vars_with_obligations(self.expr_ty(expr));
        debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);
        let mut coerce = Coerce::new(self, TypeOrigin::ExprAssignable(expr.span));
        self.commit_if_ok(|_| {
            let (ty, adjustment) =
                apply(&mut coerce, &|| Some(expr), source, target)?;
            if !adjustment.is_identity() {
                debug!("Success, coerced with {:?}", adjustment);
                assert!(!self.tables.borrow().adjustments.contains_key(&expr.id));
                self.write_adjustment(expr.id, adjustment);
            }
            Ok(ty)
        })
    }
pub fn try_coerce ( & self , expr : & hir :: Expr , target : Ty < ' tcx > ) -> RelateResult < ' tcx , Ty < ' tcx > > { let source = self . resolve_type_vars_with_obligations ( self . expr_ty ( expr ) ) ; debug ! ( " " expr source target ) ; let mut coerce = Coerce :: new ( self , TypeOrigin :: ExprAssignable ( expr . span ) ) ; self . commit_if_ok ( | _ | { let ( ty , adjustment ) = apply ( & mut coerce , & | | Some ( expr ) , source , target ) ? ; if ! adjustment . is_identity ( ) { debug ! ( " " adjustment ) ; assert ! ( self tables borrow ( ) adjustments contains_key ( expr id ) ) ; self . write_adjustment ( expr . id , adjustment ) ; } Ok ( ty ) } ) }
Attempt to coerce an expression to a type, and return the
adjusted type of the expression, if successful.
Attempt to coerce an expression to a type and return the adjusted type of the expression if successful .
&self
expr
&hir::Expr
target
Ty<'tcx>
&self
expr
&hir::Expr
target
Ty<'tcx>