diff options
| author | Ralf Jung <post@ralfj.de> | 2018-09-30 19:45:31 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-09-30 19:48:54 +0200 |
| commit | 1397836380555850ec4c34419682e312e41a4e26 (patch) | |
| tree | 7c1052fc27c94ac898856859a0912f797a71c697 | |
| parent | 1886d5fe1cdd1a016ecea9fc93d68b3052c528c8 (diff) | |
| download | rust-1397836380555850ec4c34419682e312e41a4e26.tar.gz rust-1397836380555850ec4c34419682e312e41a4e26.zip | |
do not promote comparing function pointers
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 2 | ||||
| -rw-r--r-- | src/librustc_passes/rvalue_promotion.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/issues/issue-54696.rs | 8 |
3 files changed, 10 insertions, 2 deletions
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index a6e2cad5094..2811848424b 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -750,7 +750,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } Rvalue::BinaryOp(op, ref lhs, _) => { - if let ty::RawPtr(_) = lhs.ty(self.mir, self.tcx).sty { + if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.mir, self.tcx).sty { assert!(op == BinOp::Eq || op == BinOp::Ne || op == BinOp::Le || op == BinOp::Lt || op == BinOp::Ge || op == BinOp::Gt || diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 82880046520..efe59e4face 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -348,7 +348,7 @@ fn check_expr_kind<'a, 'tcx>( return NotPromotable; } match v.tables.node_id_to_type(lhs.hir_id).sty { - ty::RawPtr(_) => { + ty::RawPtr(_) | ty::FnPtr(..) => { assert!(op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne || op.node == hir::BinOpKind::Le || op.node == hir::BinOpKind::Lt || op.node == hir::BinOpKind::Ge || op.node == hir::BinOpKind::Gt); diff --git a/src/test/run-pass/issues/issue-54696.rs b/src/test/run-pass/issues/issue-54696.rs new file mode 100644 index 00000000000..d8408ed8549 --- /dev/null +++ b/src/test/run-pass/issues/issue-54696.rs @@ -0,0 +1,8 @@ +// run-pass + +fn main() { + // We shouldn't promote this + &(main as fn() == main as fn()); + // Also check nested case + &(&(main as fn()) == &(main as fn())); +} |
