Don't ICE in CTFE if raw/fn-ptr types differ

This commit is contained in:
Michael Goulet 2024-03-08 02:57:02 +00:00
parent 1c580bcb70
commit 025ad403a9
3 changed files with 16 additions and 1 deletions

View File

@ -581,7 +581,6 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
if is_int_bool_or_char(lhs_ty) && is_int_bool_or_char(rhs_ty) {
// Int, bool, and char operations are fine.
} else if lhs_ty.is_fn_ptr() || lhs_ty.is_unsafe_ptr() {
assert_eq!(lhs_ty, rhs_ty);
assert!(matches!(
op,
BinOp::Eq

View File

@ -0,0 +1,6 @@
const fn cmp(x: fn(&'static ()), y: for<'a> fn(&'a ())) -> bool {
x == y
//~^ ERROR pointers cannot be reliably compared during const eval
}
fn main() {}

View File

@ -0,0 +1,10 @@
error: pointers cannot be reliably compared during const eval
--> $DIR/different-fn-ptr-binders-during-ctfe.rs:2:5
|
LL | x == y
| ^^^^^^
|
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
error: aborting due to 1 previous error