about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-09-09 11:17:42 +0200
committerRalf Jung <post@ralfj.de>2023-09-09 15:36:44 +0200
commitb5bab2b1cc731302fe515fa434cd30f8d0a18a17 (patch)
treea9244f78b70a4a0ff22ded346ff55d740d401356 /compiler/rustc_const_eval/src
parentf993ddc079112bc0b630b1fb38e141239b36cca6 (diff)
downloadrust-b5bab2b1cc731302fe515fa434cd30f8d0a18a17.tar.gz
rust-b5bab2b1cc731302fe515fa434cd30f8d0a18a17.zip
implement and test fn ptr ABI compatibility rules
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/interpret/terminator.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs
index 726a4e6f8a0..3ea7e77197e 100644
--- a/compiler/rustc_const_eval/src/interpret/terminator.rs
+++ b/compiler/rustc_const_eval/src/interpret/terminator.rs
@@ -298,8 +298,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
         };
         // Check if the inner type is one of the NPO-guaranteed ones.
         Ok(match inner_ty.kind() {
-            ty::Ref(..) => {
-                // Option<&T> behaves like &T
+            ty::Ref(..) | ty::FnPtr(..) => {
+                // Option<&T> behaves like &T, and same for fn()
                 inner_ty
             }
             ty::Adt(def, _)
@@ -366,6 +366,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
             return Ok(meta_ty(left) == meta_ty(right));
         }
 
+        // Compatible function pointer types.
+        if let (ty::FnPtr(..), ty::FnPtr(..)) = (caller_ty.kind(), callee_ty.kind()) {
+            return Ok(true);
+        }
+
         // Compatible integer types (in particular, usize vs ptr-sized-u32/u64).
         let int_ty = |ty: Ty<'tcx>| {
             Some(match ty.kind() {