From 7719f534196c9fe5216161e313ad7624f1beadee Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Fri, 16 Feb 2018 11:16:41 -0200 Subject: [PATCH] Replace `structurally_resolved_type` in casts check. The behaviour of `resolve_type_vars_if_possible` is simpler and infallible. --- src/librustc/ty/cast.rs | 3 +-- src/librustc_typeck/check/cast.rs | 10 +++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/librustc/ty/cast.rs b/src/librustc/ty/cast.rs index c118b7a4692e..3ba79d91964a 100644 --- a/src/librustc/ty/cast.rs +++ b/src/librustc/ty/cast.rs @@ -20,7 +20,6 @@ use syntax::ast; pub enum IntTy { U(ast::UintTy), I, - Ivar, CEnum, Bool, Char @@ -64,7 +63,7 @@ impl<'tcx> CastTy<'tcx> { ty::TyBool => Some(CastTy::Int(IntTy::Bool)), ty::TyChar => Some(CastTy::Int(IntTy::Char)), ty::TyInt(_) => Some(CastTy::Int(IntTy::I)), - ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::Ivar)), + ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::I)), ty::TyInfer(ty::InferTy::FloatVar(_)) => Some(CastTy::Float), ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))), ty::TyFloat(_) => Some(CastTy::Float), diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index e4bad8349ea2..31f418df902b 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -389,8 +389,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { } pub fn check(mut self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) { - self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty); - self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty); + self.expr_ty = fcx.resolve_type_vars_if_possible(&self.expr_ty); + self.cast_ty = fcx.resolve_type_vars_if_possible(&self.cast_ty); debug!("check_cast({}, {:?} as {:?})", self.expr.id, @@ -484,11 +484,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { ty::TypeVariants::TyInfer(t) => { match t { ty::InferTy::IntVar(_) | - ty::InferTy::FloatVar(_) | - ty::InferTy::FreshIntTy(_) | - ty::InferTy::FreshFloatTy(_) => { - Err(CastError::NeedDeref) - } + ty::InferTy::FloatVar(_) => Err(CastError::NeedDeref), _ => Err(CastError::NeedViaPtr), } }