Skip to content

Commit 1397836

Browse files
committed
do not promote comparing function pointers
1 parent 1886d5f commit 1397836

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/librustc_mir/transform/qualify_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
750750
}
751751

752752
Rvalue::BinaryOp(op, ref lhs, _) => {
753-
if let ty::RawPtr(_) = lhs.ty(self.mir, self.tcx).sty {
753+
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.mir, self.tcx).sty {
754754
assert!(op == BinOp::Eq || op == BinOp::Ne ||
755755
op == BinOp::Le || op == BinOp::Lt ||
756756
op == BinOp::Ge || op == BinOp::Gt ||

src/librustc_passes/rvalue_promotion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ fn check_expr_kind<'a, 'tcx>(
348348
return NotPromotable;
349349
}
350350
match v.tables.node_id_to_type(lhs.hir_id).sty {
351-
ty::RawPtr(_) => {
351+
ty::RawPtr(_) | ty::FnPtr(..) => {
352352
assert!(op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne ||
353353
op.node == hir::BinOpKind::Le || op.node == hir::BinOpKind::Lt ||
354354
op.node == hir::BinOpKind::Ge || op.node == hir::BinOpKind::Gt);
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-pass
2+
3+
fn main() {
4+
// We shouldn't promote this
5+
&(main as fn() == main as fn());
6+
// Also check nested case
7+
&(&(main as fn()) == &(main as fn()));
8+
}

0 commit comments

Comments
 (0)