Skip to content

Commit f0a5a4b

Browse files
authored
Rollup merge of rust-lang#148641 - oli-obk:push-olzwqxsmnxmz, r=jackh726
Add a diagnostic attribute for special casing const bound errors for non-const impls Somewhat of a follow-up to rust-lang#144194 My plan is to resolve https://github.com/rust-lang/rust/blob/f4e19c68786211f3c3cf2593442629599678800a/compiler/rustc_hir_typeck/src/callee.rs#L907-913 but doing so without being able to mark impls the way I do in this PR wrould cause all nice diagnostics about for loops and pointer comparisons to just be a `*const u32 does not implement [const] PartialEq` errors.
2 parents 430b4c5 + 997f256 commit f0a5a4b

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
#![feature(decl_macro)]
150150
#![feature(deprecated_suggestion)]
151151
#![feature(derive_const)]
152+
#![feature(diagnostic_on_const)]
152153
#![feature(doc_cfg)]
153154
#![feature(doc_notable_trait)]
154155
#![feature(extern_types)]

core/src/ptr/const_ptr.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,10 @@ impl<T, const N: usize> *const [T; N] {
15671567

15681568
/// Pointer equality is by address, as produced by the [`<*const T>::addr`](pointer::addr) method.
15691569
#[stable(feature = "rust1", since = "1.0.0")]
1570+
#[diagnostic::on_const(
1571+
message = "pointers cannot be reliably compared during const eval",
1572+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
1573+
)]
15701574
impl<T: PointeeSized> PartialEq for *const T {
15711575
#[inline]
15721576
#[allow(ambiguous_wide_pointer_comparisons)]
@@ -1577,10 +1581,18 @@ impl<T: PointeeSized> PartialEq for *const T {
15771581

15781582
/// Pointer equality is an equivalence relation.
15791583
#[stable(feature = "rust1", since = "1.0.0")]
1584+
#[diagnostic::on_const(
1585+
message = "pointers cannot be reliably compared during const eval",
1586+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
1587+
)]
15801588
impl<T: PointeeSized> Eq for *const T {}
15811589

15821590
/// Pointer comparison is by address, as produced by the `[`<*const T>::addr`](pointer::addr)` method.
15831591
#[stable(feature = "rust1", since = "1.0.0")]
1592+
#[diagnostic::on_const(
1593+
message = "pointers cannot be reliably compared during const eval",
1594+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
1595+
)]
15841596
impl<T: PointeeSized> Ord for *const T {
15851597
#[inline]
15861598
#[allow(ambiguous_wide_pointer_comparisons)]
@@ -1597,6 +1609,10 @@ impl<T: PointeeSized> Ord for *const T {
15971609

15981610
/// Pointer comparison is by address, as produced by the `[`<*const T>::addr`](pointer::addr)` method.
15991611
#[stable(feature = "rust1", since = "1.0.0")]
1612+
#[diagnostic::on_const(
1613+
message = "pointers cannot be reliably compared during const eval",
1614+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
1615+
)]
16001616
impl<T: PointeeSized> PartialOrd for *const T {
16011617
#[inline]
16021618
#[allow(ambiguous_wide_pointer_comparisons)]

core/src/ptr/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,23 +2520,39 @@ pub fn hash<T: PointeeSized, S: hash::Hasher>(hashee: *const T, into: &mut S) {
25202520
}
25212521

25222522
#[stable(feature = "fnptr_impls", since = "1.4.0")]
2523+
#[diagnostic::on_const(
2524+
message = "pointers cannot be reliably compared during const eval",
2525+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
2526+
)]
25232527
impl<F: FnPtr> PartialEq for F {
25242528
#[inline]
25252529
fn eq(&self, other: &Self) -> bool {
25262530
self.addr() == other.addr()
25272531
}
25282532
}
25292533
#[stable(feature = "fnptr_impls", since = "1.4.0")]
2534+
#[diagnostic::on_const(
2535+
message = "pointers cannot be reliably compared during const eval",
2536+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
2537+
)]
25302538
impl<F: FnPtr> Eq for F {}
25312539

25322540
#[stable(feature = "fnptr_impls", since = "1.4.0")]
2541+
#[diagnostic::on_const(
2542+
message = "pointers cannot be reliably compared during const eval",
2543+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
2544+
)]
25332545
impl<F: FnPtr> PartialOrd for F {
25342546
#[inline]
25352547
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
25362548
self.addr().partial_cmp(&other.addr())
25372549
}
25382550
}
25392551
#[stable(feature = "fnptr_impls", since = "1.4.0")]
2552+
#[diagnostic::on_const(
2553+
message = "pointers cannot be reliably compared during const eval",
2554+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
2555+
)]
25402556
impl<F: FnPtr> Ord for F {
25412557
#[inline]
25422558
fn cmp(&self, other: &Self) -> Ordering {

core/src/ptr/mut_ptr.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,10 @@ impl<T, const N: usize> *mut [T; N] {
20002000

20012001
/// Pointer equality is by address, as produced by the [`<*mut T>::addr`](pointer::addr) method.
20022002
#[stable(feature = "rust1", since = "1.0.0")]
2003+
#[diagnostic::on_const(
2004+
message = "pointers cannot be reliably compared during const eval",
2005+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
2006+
)]
20032007
impl<T: PointeeSized> PartialEq for *mut T {
20042008
#[inline(always)]
20052009
#[allow(ambiguous_wide_pointer_comparisons)]
@@ -2010,10 +2014,18 @@ impl<T: PointeeSized> PartialEq for *mut T {
20102014

20112015
/// Pointer equality is an equivalence relation.
20122016
#[stable(feature = "rust1", since = "1.0.0")]
2017+
#[diagnostic::on_const(
2018+
message = "pointers cannot be reliably compared during const eval",
2019+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
2020+
)]
20132021
impl<T: PointeeSized> Eq for *mut T {}
20142022

20152023
/// Pointer comparison is by address, as produced by the [`<*mut T>::addr`](pointer::addr) method.
20162024
#[stable(feature = "rust1", since = "1.0.0")]
2025+
#[diagnostic::on_const(
2026+
message = "pointers cannot be reliably compared during const eval",
2027+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
2028+
)]
20172029
impl<T: PointeeSized> Ord for *mut T {
20182030
#[inline]
20192031
#[allow(ambiguous_wide_pointer_comparisons)]
@@ -2030,6 +2042,10 @@ impl<T: PointeeSized> Ord for *mut T {
20302042

20312043
/// Pointer comparison is by address, as produced by the [`<*mut T>::addr`](pointer::addr) method.
20322044
#[stable(feature = "rust1", since = "1.0.0")]
2045+
#[diagnostic::on_const(
2046+
message = "pointers cannot be reliably compared during const eval",
2047+
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
2048+
)]
20332049
impl<T: PointeeSized> PartialOrd for *mut T {
20342050
#[inline(always)]
20352051
#[allow(ambiguous_wide_pointer_comparisons)]

0 commit comments

Comments
 (0)