/// Reifies a cast check to be checked once we have full type information for
/// a function context.
pub struct CastCheck<'tcx> {
- expr: hir::Expr,
+ expr: &'tcx hir::Expr,
expr_ty: Ty<'tcx>,
cast_ty: Ty<'tcx>,
span: Span,
}
impl<'tcx> CastCheck<'tcx> {
- pub fn new(expr: hir::Expr, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, span: Span)
+ pub fn new(expr: &'tcx hir::Expr, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, span: Span)
-> CastCheck<'tcx> {
CastCheck {
expr: expr,
(None, Some(t_cast)) => {
if let ty::TyFnDef(_, _, f) = self.expr_ty.sty {
// Attempt a coercion to a fn pointer type.
- let res = coercion::try(fcx, &self.expr,
+ let res = coercion::try(fcx, self.expr,
self.expr_ty, fcx.tcx().mk_ty(ty::TyFnPtr(f)));
if !res.is_ok() {
return Err(CastError::NonScalar);
}
fn try_coercion_cast<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) -> bool {
- coercion::try(fcx, &self.expr, self.expr_ty, self.cast_ty).is_ok()
+ coercion::try(fcx, self.expr, self.expr_ty, self.cast_ty).is_ok()
}
}
}
// FIXME(arielb1): use this instead of field.ty everywhere
+ // Only for fields! Returns <none> for methods>
+ // Indifferent to privacy flags
pub fn field_ty(&self,
span: Span,
field: ty::FieldDef<'tcx>,
&field.ty(self.tcx(), substs))
}
- // Only for fields! Returns <none> for methods>
- // Indifferent to privacy flags
fn check_casts(&self) {
let mut deferred_cast_checks = self.inh.deferred_cast_checks.borrow_mut();
for cast in deferred_cast_checks.drain(..) {
// Defer other checks until we're done type checking.
let mut deferred_cast_checks = fcx.inh.deferred_cast_checks.borrow_mut();
- let cast_check = cast::CastCheck::new((**e).clone(), t_expr, t_cast, expr.span);
+ let cast_check = cast::CastCheck::new(e, t_expr, t_cast, expr.span);
deferred_cast_checks.push(cast_check);
}
}