Skip to content

Commit

Permalink
do not promote comparing function pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 30, 2018
1 parent 1886d5f commit 1397836
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/rvalue_promotion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/test/run-pass/issues/issue-54696.rs
Original file line number Diff line number Diff line change
@@ -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()));
}

0 comments on commit 1397836

Please sign in to comment.