Skip to content

Commit 2d68ae8

Browse files
committed
Auto merge of #48270 - leodasvacas:refactor-casts, r=<try>
Replace `structurally_resolved_type` in casts check. The behaviour of `resolve_type_vars_if_possible` is simpler and infallible. Other minor refactorings. I'm not sure if this is backwards compatible, in theory resolving obligations between two cast checks could solve a dependency between them, but I don't know if that's actually possible and it doesn't sound like something we'd want to support.
2 parents 58a8e0c + 1efd547 commit 2d68ae8

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/librustc/ty/cast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use syntax::ast;
2020
pub enum IntTy {
2121
U(ast::UintTy),
2222
I,
23-
Ivar,
2423
CEnum,
2524
Bool,
2625
Char
@@ -64,7 +63,7 @@ impl<'tcx> CastTy<'tcx> {
6463
ty::TyBool => Some(CastTy::Int(IntTy::Bool)),
6564
ty::TyChar => Some(CastTy::Int(IntTy::Char)),
6665
ty::TyInt(_) => Some(CastTy::Int(IntTy::I)),
67-
ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::Ivar)),
66+
ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::I)),
6867
ty::TyInfer(ty::InferTy::FloatVar(_)) => Some(CastTy::Float),
6968
ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))),
7069
ty::TyFloat(_) => Some(CastTy::Float),

src/librustc_typeck/check/cast.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
392392
}
393393

394394
pub fn check(mut self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) {
395-
self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty);
396-
self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty);
395+
self.expr_ty = fcx.resolve_type_vars_if_possible(&self.expr_ty);
396+
self.cast_ty = fcx.resolve_type_vars_if_possible(&self.cast_ty);
397397

398398
debug!("check_cast({}, {:?} as {:?})",
399399
self.expr.id,
@@ -488,11 +488,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
488488
ty::TypeVariants::TyInfer(t) => {
489489
match t {
490490
ty::InferTy::IntVar(_) |
491-
ty::InferTy::FloatVar(_) |
492-
ty::InferTy::FreshIntTy(_) |
493-
ty::InferTy::FreshFloatTy(_) => {
494-
Err(CastError::NeedDeref)
495-
}
491+
ty::InferTy::FloatVar(_) => Err(CastError::NeedDeref),
496492
_ => Err(CastError::NeedViaPtr),
497493
}
498494
}

0 commit comments

Comments
 (0)