about summary refs log tree commit diff
path: root/src/librustc_passes
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-03-09 17:18:17 +0100
committerGitHub <noreply@github.com>2019-03-09 17:18:17 +0100
commit0c4cb48e03af0cc7481b76ada343c092bf6dfdfd (patch)
tree2193e91a5f59c0de56d01cc59af23bb6cd10d6bb /src/librustc_passes
parent5e52010304e885f8991e73223c22051503fa1d13 (diff)
parent9902f8c3c2e89c87ab25a543e12c851bef955608 (diff)
downloadrust-0c4cb48e03af0cc7481b76ada343c092bf6dfdfd.tar.gz
rust-0c4cb48e03af0cc7481b76ada343c092bf6dfdfd.zip
Rollup merge of #58670 - saleemjaffer:refactor_typecast_check_kinds, r=oli-obk
fixes rust-lang#52482
Diffstat (limited to 'src/librustc_passes')
-rw-r--r--src/librustc_passes/rvalue_promotion.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs
index af01e38cb54..9de022a4021 100644
--- a/src/librustc_passes/rvalue_promotion.rs
+++ b/src/librustc_passes/rvalue_promotion.rs
@@ -14,7 +14,7 @@
 // - It's not possible to take the address of a static item with unsafe interior. This is enforced
 // by borrowck::gather_loans
 
-use rustc::ty::cast::CastKind;
+use rustc::ty::cast::CastTy;
 use rustc::hir::def::{Def, CtorKind};
 use rustc::hir::def_id::DefId;
 use rustc::middle::expr_use_visitor as euv;
@@ -318,15 +318,12 @@ fn check_expr_kind<'a, 'tcx>(
         hir::ExprKind::Cast(ref from, _) => {
             let expr_promotability = v.check_expr(from);
             debug!("Checking const cast(id={})", from.hir_id);
-            match v.tables.cast_kinds().get(from.hir_id) {
-                None => {
-                    v.tcx.sess.delay_span_bug(e.span, "no kind for cast");
-                    NotPromotable
-                },
-                Some(&CastKind::PtrAddrCast) | Some(&CastKind::FnPtrAddrCast) => {
-                    NotPromotable
-                }
-                _ => expr_promotability
+            let cast_in = CastTy::from_ty(v.tables.expr_ty(from));
+            let cast_out = CastTy::from_ty(v.tables.expr_ty(e));
+            match (cast_in, cast_out) {
+                (Some(CastTy::FnPtr), Some(CastTy::Int(_))) |
+                (Some(CastTy::Ptr(_)), Some(CastTy::Int(_))) => NotPromotable,
+                (_, _) => expr_promotability
             }
         }
         hir::ExprKind::Path(ref qpath) => {