Skip to content

Commit 3ff4c34

Browse files
committed
typeck: don't wastefully clone expressions for cast checks.
1 parent dbab236 commit 3ff4c34

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/librustc_typeck/check/cast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use syntax::ast;
5555
/// Reifies a cast check to be checked once we have full type information for
5656
/// a function context.
5757
pub struct CastCheck<'tcx> {
58-
expr: hir::Expr,
58+
expr: &'tcx hir::Expr,
5959
expr_ty: Ty<'tcx>,
6060
cast_ty: Ty<'tcx>,
6161
span: Span,
@@ -109,7 +109,7 @@ enum CastError {
109109
}
110110

111111
impl<'tcx> CastCheck<'tcx> {
112-
pub fn new(expr: hir::Expr, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, span: Span)
112+
pub fn new(expr: &'tcx hir::Expr, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, span: Span)
113113
-> CastCheck<'tcx> {
114114
CastCheck {
115115
expr: expr,
@@ -239,7 +239,7 @@ impl<'tcx> CastCheck<'tcx> {
239239
(None, Some(t_cast)) => {
240240
if let ty::TyFnDef(_, _, f) = self.expr_ty.sty {
241241
// Attempt a coercion to a fn pointer type.
242-
let res = coercion::try(fcx, &self.expr,
242+
let res = coercion::try(fcx, self.expr,
243243
self.expr_ty, fcx.tcx().mk_ty(ty::TyFnPtr(f)));
244244
if !res.is_ok() {
245245
return Err(CastError::NonScalar);
@@ -390,7 +390,7 @@ impl<'tcx> CastCheck<'tcx> {
390390
}
391391

392392
fn try_coercion_cast<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) -> bool {
393-
coercion::try(fcx, &self.expr, self.expr_ty, self.cast_ty).is_ok()
393+
coercion::try(fcx, self.expr, self.expr_ty, self.cast_ty).is_ok()
394394
}
395395

396396
}

src/librustc_typeck/check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17011701
}
17021702

17031703
// FIXME(arielb1): use this instead of field.ty everywhere
1704+
// Only for fields! Returns <none> for methods>
1705+
// Indifferent to privacy flags
17041706
pub fn field_ty(&self,
17051707
span: Span,
17061708
field: ty::FieldDef<'tcx>,
@@ -1711,8 +1713,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17111713
&field.ty(self.tcx(), substs))
17121714
}
17131715

1714-
// Only for fields! Returns <none> for methods>
1715-
// Indifferent to privacy flags
17161716
fn check_casts(&self) {
17171717
let mut deferred_cast_checks = self.inh.deferred_cast_checks.borrow_mut();
17181718
for cast in deferred_cast_checks.drain(..) {
@@ -3511,7 +3511,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
35113511

35123512
// Defer other checks until we're done type checking.
35133513
let mut deferred_cast_checks = fcx.inh.deferred_cast_checks.borrow_mut();
3514-
let cast_check = cast::CastCheck::new((**e).clone(), t_expr, t_cast, expr.span);
3514+
let cast_check = cast::CastCheck::new(e, t_expr, t_cast, expr.span);
35153515
deferred_cast_checks.push(cast_check);
35163516
}
35173517
}

0 commit comments

Comments
 (0)