From 01948e2f45acefc336501b9b9f836845fc566774 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Mon, 13 Dec 2021 12:35:55 +0300 Subject: [PATCH 1/5] Looser check for binary_op_overflow --- compiler/rustc_const_eval/src/interpret/operator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index a90582fc33820..a3094c8991c7d 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -330,7 +330,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { _ if left.layout.ty.is_any_ptr() => { // The RHS type must be the same *or an integer type* (for `Offset`). assert!( - right.layout.ty == left.layout.ty || right.layout.ty.is_integral(), + right.layout.ty.is_any_ptr()|| right.layout.ty.is_integral(), "Unexpected types for BinOp: {:?} {:?} {:?}", left.layout.ty, bin_op, From a01b13dede8f4197520ac136d87a831ddfadc9c4 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Mon, 13 Dec 2021 12:59:31 +0300 Subject: [PATCH 2/5] formatting --- compiler/rustc_const_eval/src/interpret/operator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index a3094c8991c7d..58a51b15faa6c 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -330,7 +330,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { _ if left.layout.ty.is_any_ptr() => { // The RHS type must be the same *or an integer type* (for `Offset`). assert!( - right.layout.ty.is_any_ptr()|| right.layout.ty.is_integral(), + right.layout.ty.is_any_ptr() || right.layout.ty.is_integral(), "Unexpected types for BinOp: {:?} {:?} {:?}", left.layout.ty, bin_op, From b6c80985bd5c63ebf5f720450c4208fabc20af73 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Tue, 14 Dec 2021 00:15:50 +0300 Subject: [PATCH 3/5] Add regression test and comment --- compiler/rustc_const_eval/src/interpret/operator.rs | 3 ++- src/test/ui/binop/binary-op-on-fn-ptr-eq.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/binop/binary-op-on-fn-ptr-eq.rs diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index 58a51b15faa6c..3b8b65a50d21f 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -328,7 +328,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.binary_int_op(bin_op, l, left.layout, r, right.layout) } _ if left.layout.ty.is_any_ptr() => { - // The RHS type must be the same *or an integer type* (for `Offset`). + // The RHS type must be a `pointer` *or an integer type* (for `Offset`). + // (This is workaround for the issue #91636) assert!( right.layout.ty.is_any_ptr() || right.layout.ty.is_integral(), "Unexpected types for BinOp: {:?} {:?} {:?}", diff --git a/src/test/ui/binop/binary-op-on-fn-ptr-eq.rs b/src/test/ui/binop/binary-op-on-fn-ptr-eq.rs new file mode 100644 index 0000000000000..188a27a1dcd45 --- /dev/null +++ b/src/test/ui/binop/binary-op-on-fn-ptr-eq.rs @@ -0,0 +1,8 @@ +// Tests equality between supertype and subtype of a function +// See the issue #91636 +fn foo(_a: &str) {} + +fn main() { + let x = foo as fn(&'static str); + let _ = x == foo; +} From b85762f436a2ef12e2a0a36ac3a61d680871b3cc Mon Sep 17 00:00:00 2001 From: ouz-a Date: Tue, 14 Dec 2021 01:19:10 +0300 Subject: [PATCH 4/5] test should pass :sweat_smile: --- src/test/ui/binop/binary-op-on-fn-ptr-eq.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/binop/binary-op-on-fn-ptr-eq.rs b/src/test/ui/binop/binary-op-on-fn-ptr-eq.rs index 188a27a1dcd45..8e20640b58d94 100644 --- a/src/test/ui/binop/binary-op-on-fn-ptr-eq.rs +++ b/src/test/ui/binop/binary-op-on-fn-ptr-eq.rs @@ -1,3 +1,4 @@ +// run-pass // Tests equality between supertype and subtype of a function // See the issue #91636 fn foo(_a: &str) {} From a5054e3858150384c30ce71afc76ca9c57c8cec2 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Tue, 14 Dec 2021 19:29:29 +0300 Subject: [PATCH 5/5] comment update --- compiler/rustc_const_eval/src/interpret/operator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index 3b8b65a50d21f..48c90e1881a9a 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -329,7 +329,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } _ if left.layout.ty.is_any_ptr() => { // The RHS type must be a `pointer` *or an integer type* (for `Offset`). - // (This is workaround for the issue #91636) + // (Even when both sides are pointers, their type might differ, see issue #91636) assert!( right.layout.ty.is_any_ptr() || right.layout.ty.is_integral(), "Unexpected types for BinOp: {:?} {:?} {:?}",