Skip to content

Commit

Permalink
Replace structurally_resolved_type in casts check.
Browse files Browse the repository at this point in the history
The behaviour of `resolve_type_vars_if_possible` is simpler and
infallible.
  • Loading branch information
leoyvens committed Mar 22, 2018
1 parent 5092c6b commit 7719f53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/librustc/ty/cast.rs
Expand Up @@ -20,7 +20,6 @@ use syntax::ast;
pub enum IntTy {
U(ast::UintTy),
I,
Ivar,
CEnum,
Bool,
Char
Expand Down Expand Up @@ -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),
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_typeck/check/cast.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
}
}
Expand Down

0 comments on commit 7719f53

Please sign in to comment.