typeck: don't wastefully clone expressions for cast checks.
This commit is contained in:
parent
dbab236a9e
commit
3ff4c347c7
2 changed files with 7 additions and 7 deletions
|
|
@ -55,7 +55,7 @@ use syntax::ast;
|
|||
/// 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,
|
||||
|
|
@ -109,7 +109,7 @@ enum CastError {
|
|||
}
|
||||
|
||||
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,
|
||||
|
|
@ -239,7 +239,7 @@ impl<'tcx> CastCheck<'tcx> {
|
|||
(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);
|
||||
|
|
@ -390,7 +390,7 @@ impl<'tcx> CastCheck<'tcx> {
|
|||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1701,6 +1701,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// 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>,
|
||||
|
|
@ -1711,8 +1713,6 @@ impl<'a, 'tcx> FnCtxt<'a, '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(..) {
|
||||
|
|
@ -3511,7 +3511,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue