Skip to content

Commit 9e88b48

Browse files
committed
Refer just to the issue in the raw ptr cmp diagnostic instead of explaining everything in the diagnostic
1 parent 84f1d73 commit 9e88b48

File tree

7 files changed

+9
-31
lines changed

7 files changed

+9
-31
lines changed

src/librustc_mir/transform/check_consts/ops.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -287,26 +287,12 @@ impl NonConstOp for RawPtrComparison {
287287
fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
288288
let mut err = ccx.tcx.sess.struct_span_err(
289289
span,
290-
"pointers cannot be compared in a meaningful way during const eval.",
290+
"pointers cannot be reliably compared during const eval.",
291291
);
292292
err.note(
293293
"see issue #53020 <https://github.com/rust-lang/rust/issues/53020> \
294294
for more information",
295295
);
296-
err.note(
297-
"It is conceptually impossible for const eval to know in all cases whether two \
298-
pointers are equal. While sometimes it is clear (the address of a non-zst static item \
299-
is never equal to the address of another non-zst static item), comparing an integer \
300-
address with any allocation's address is impossible to do at compile-time.",
301-
);
302-
if ccx.tcx.sess.parse_sess.unstable_features.is_nightly_build() {
303-
err.note(
304-
"That said, there's the `<*const T>::guaranteed_eq` intrinsic which returns `true` \
305-
for all comparisons where CTFE is sure that two addresses are equal. The mirror \
306-
intrinsic `<*const T>::guaranteed_ne` returns `true` for all comparisons where \
307-
CTFE is sure that two addresses are inequal.",
308-
);
309-
}
310296
err.emit();
311297
}
312298
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {}
22

33
// unconst and bad, will thus error in miri
4-
const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; //~ ERROR cannot be compared
4+
const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; //~ ERROR cannot be reliably compared
55
// unconst and bad, will thus error in miri
6-
const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; //~ ERROR cannot be compared
6+
const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; //~ ERROR cannot be reliably compared
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
error: pointers cannot be compared in a meaningful way during const eval.
1+
error: pointers cannot be reliably compared during const eval.
22
--> $DIR/const_raw_ptr_ops.rs:4:26
33
|
44
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
8-
= 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.
9-
= 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.
108

11-
error: pointers cannot be compared in a meaningful way during const eval.
9+
error: pointers cannot be reliably compared during const eval.
1210
--> $DIR/const_raw_ptr_ops.rs:6:27
1311
|
1412
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
1513
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1614
|
1715
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
18-
= 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.
19-
= 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.
2016

2117
error: aborting due to 2 previous errors
2218

src/test/ui/error-codes/E0395.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ static FOO: i32 = 42;
22
static BAR: i32 = 42;
33

44
static BAZ: bool = unsafe { (&FOO as *const i32) == (&BAR as *const i32) };
5-
//~^ ERROR pointers cannot be compared in a meaningful way during const eval
5+
//~^ ERROR pointers cannot be reliably compared during const eval
66

77
fn main() {
88
}

src/test/ui/error-codes/E0395.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
error: pointers cannot be compared in a meaningful way during const eval.
1+
error: pointers cannot be reliably compared during const eval.
22
--> $DIR/E0395.rs:4:29
33
|
44
LL | static BAZ: bool = unsafe { (&FOO as *const i32) == (&BAR as *const i32) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
8-
= 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.
9-
= 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.
108

119
error: aborting due to previous error
1210

src/test/ui/issues/issue-25826.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn id<T>(t: T) -> T { t }
22
fn main() {
33
const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
4-
//~^ ERROR pointers cannot be compared in a meaningful way during const eval
4+
//~^ ERROR pointers cannot be reliably compared during const eval
55
println!("{}", A);
66
}

src/test/ui/issues/issue-25826.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
error: pointers cannot be compared in a meaningful way during const eval.
1+
error: pointers cannot be reliably compared during const eval.
22
--> $DIR/issue-25826.rs:3:30
33
|
44
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
8-
= 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.
9-
= 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.
108

119
error: aborting due to previous error
1210

0 commit comments

Comments
 (0)