Refer just to the issue in the raw ptr cmp diagnostic instead of explaining everything in the diagnostic
This commit is contained in:
parent
84f1d73182
commit
9e88b48133
@ -287,26 +287,12 @@ impl NonConstOp for RawPtrComparison {
|
||||
fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
|
||||
let mut err = ccx.tcx.sess.struct_span_err(
|
||||
span,
|
||||
"pointers cannot be compared in a meaningful way during const eval.",
|
||||
"pointers cannot be reliably compared during const eval.",
|
||||
);
|
||||
err.note(
|
||||
"see issue #53020 <https://github.com/rust-lang/rust/issues/53020> \
|
||||
for more information",
|
||||
);
|
||||
err.note(
|
||||
"It is conceptually impossible for const eval to know in all cases whether two \
|
||||
pointers are equal. While sometimes it is clear (the address of a non-zst static item \
|
||||
is never equal to the address of another non-zst static item), comparing an integer \
|
||||
address with any allocation's address is impossible to do at compile-time.",
|
||||
);
|
||||
if ccx.tcx.sess.parse_sess.unstable_features.is_nightly_build() {
|
||||
err.note(
|
||||
"That said, there's the `<*const T>::guaranteed_eq` intrinsic which returns `true` \
|
||||
for all comparisons where CTFE is sure that two addresses are equal. The mirror \
|
||||
intrinsic `<*const T>::guaranteed_ne` returns `true` for all comparisons where \
|
||||
CTFE is sure that two addresses are inequal.",
|
||||
);
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
fn main() {}
|
||||
|
||||
// unconst and bad, will thus error in miri
|
||||
const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; //~ ERROR cannot be compared
|
||||
const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; //~ ERROR cannot be reliably compared
|
||||
// unconst and bad, will thus error in miri
|
||||
const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; //~ ERROR cannot be compared
|
||||
const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; //~ ERROR cannot be reliably compared
|
||||
|
@ -1,22 +1,18 @@
|
||||
error: pointers cannot be compared in a meaningful way during const eval.
|
||||
error: pointers cannot be reliably compared during const eval.
|
||||
--> $DIR/const_raw_ptr_ops.rs:4:26
|
||||
|
|
||||
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
|
||||
= note: It is conceptually impossible for const eval to know in all cases whether two pointers are equal. While sometimes it is clear (the address of a non-zst static item is never equal to the address of another non-zst static item), comparing an integer address with any allocation's address is impossible to do at compile-time.
|
||||
= note: That said, there's the `<*const T>::guaranteed_eq` intrinsic which returns `true` for all comparisons where CTFE is sure that two addresses are equal. The mirror intrinsic `<*const T>::guaranteed_ne` returns `true` for all comparisons where CTFE is sure that two addresses are inequal.
|
||||
|
||||
error: pointers cannot be compared in a meaningful way during const eval.
|
||||
error: pointers cannot be reliably compared during const eval.
|
||||
--> $DIR/const_raw_ptr_ops.rs:6:27
|
||||
|
|
||||
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
|
||||
= note: It is conceptually impossible for const eval to know in all cases whether two pointers are equal. While sometimes it is clear (the address of a non-zst static item is never equal to the address of another non-zst static item), comparing an integer address with any allocation's address is impossible to do at compile-time.
|
||||
= note: That said, there's the `<*const T>::guaranteed_eq` intrinsic which returns `true` for all comparisons where CTFE is sure that two addresses are equal. The mirror intrinsic `<*const T>::guaranteed_ne` returns `true` for all comparisons where CTFE is sure that two addresses are inequal.
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
static BAR: i32 = 42;
|
||||
|
||||
static BAZ: bool = unsafe { (&FOO as *const i32) == (&BAR as *const i32) };
|
||||
//~^ ERROR pointers cannot be compared in a meaningful way during const eval
|
||||
//~^ ERROR pointers cannot be reliably compared during const eval
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
error: pointers cannot be compared in a meaningful way during const eval.
|
||||
error: pointers cannot be reliably compared during const eval.
|
||||
--> $DIR/E0395.rs:4:29
|
||||
|
|
||||
LL | static BAZ: bool = unsafe { (&FOO as *const i32) == (&BAR as *const i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
|
||||
= note: It is conceptually impossible for const eval to know in all cases whether two pointers are equal. While sometimes it is clear (the address of a non-zst static item is never equal to the address of another non-zst static item), comparing an integer address with any allocation's address is impossible to do at compile-time.
|
||||
= note: That said, there's the `<*const T>::guaranteed_eq` intrinsic which returns `true` for all comparisons where CTFE is sure that two addresses are equal. The mirror intrinsic `<*const T>::guaranteed_ne` returns `true` for all comparisons where CTFE is sure that two addresses are inequal.
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
fn id<T>(t: T) -> T { t }
|
||||
fn main() {
|
||||
const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
|
||||
//~^ ERROR pointers cannot be compared in a meaningful way during const eval
|
||||
//~^ ERROR pointers cannot be reliably compared during const eval
|
||||
println!("{}", A);
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
error: pointers cannot be compared in a meaningful way during const eval.
|
||||
error: pointers cannot be reliably compared during const eval.
|
||||
--> $DIR/issue-25826.rs:3:30
|
||||
|
|
||||
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
|
||||
= note: It is conceptually impossible for const eval to know in all cases whether two pointers are equal. While sometimes it is clear (the address of a non-zst static item is never equal to the address of another non-zst static item), comparing an integer address with any allocation's address is impossible to do at compile-time.
|
||||
= note: That said, there's the `<*const T>::guaranteed_eq` intrinsic which returns `true` for all comparisons where CTFE is sure that two addresses are equal. The mirror intrinsic `<*const T>::guaranteed_ne` returns `true` for all comparisons where CTFE is sure that two addresses are inequal.
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user