Skip to content

Commit bae9270

Browse files
authored
Rollup merge of #91856 - ouz-a:master, r=oli-obk
Looser check for overflowing_binary_op Fix for issue #91636 tight check resulted in ICE, this makes the check a little looser. It seems `eq` allows comparing of `supertype` and `subtype` if `lhs = supertype` and `rhs = subtype` but not vice versa, is this intended behavior ?
2 parents 6a94918 + a5054e3 commit bae9270

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Diff for: compiler/rustc_const_eval/src/interpret/operator.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
328328
self.binary_int_op(bin_op, l, left.layout, r, right.layout)
329329
}
330330
_ if left.layout.ty.is_any_ptr() => {
331-
// The RHS type must be the same *or an integer type* (for `Offset`).
331+
// The RHS type must be a `pointer` *or an integer type* (for `Offset`).
332+
// (Even when both sides are pointers, their type might differ, see issue #91636)
332333
assert!(
333-
right.layout.ty == left.layout.ty || right.layout.ty.is_integral(),
334+
right.layout.ty.is_any_ptr() || right.layout.ty.is_integral(),
334335
"Unexpected types for BinOp: {:?} {:?} {:?}",
335336
left.layout.ty,
336337
bin_op,

Diff for: src/test/ui/binop/binary-op-on-fn-ptr-eq.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-pass
2+
// Tests equality between supertype and subtype of a function
3+
// See the issue #91636
4+
fn foo(_a: &str) {}
5+
6+
fn main() {
7+
let x = foo as fn(&'static str);
8+
let _ = x == foo;
9+
}

0 commit comments

Comments
 (0)