Skip to content

Don't specialize on maybe-const - #162138

Open
clarfonthey wants to merge 1 commit into
rust-lang:mainfrom
clarfonthey:min-specialization-const
Open

clarfonthey wants to merge 1 commit into
rust-lang:mainfrom
clarfonthey:min-specialization-const

Conversation

@clarfonthey

@clarfonthey clarfonthey commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Related: #148200

Was mentioned at a T-types meeting. Immediately an issue with this due to pointers being not const-comparable, but wanted to at least open a PR with the change to discuss.

Note that currently the following impls are notable:

  • const trait BytewiseEq<Rhs = Self>: [const] PartialEq<Rhs> + Sized
  • const trait AlwaysApplicableOrd: [const] SliceOrd + [const] Ord {}
  • const unsafe trait UnsignedBytewiseOrd: [const] Ord {}
  • const unsafe trait TrustedStep: [const] Step + Copy {}

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 1, 2026
@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, joboet

[] u8, [] u16, [] u32, [] u64, [] u128, [] usize,
[] i8, [] i16, [] i32, [] i64, [] i128, [] isize,
[] bool, [] char,
[T: ?Sized] *const T, [T: ?Sized] *mut T,

@clarfonthey clarfonthey Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line of shame that makes this change not work atm.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@clarfonthey clarfonthey added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Sep 1, 2026
@Mark-Simulacrum

Copy link
Copy Markdown
Member

Maybe this should be reviewed by Types? It's not very clear to me (a) what problems this solves or (b) how we avoid them elsewhere -- presumably we should have the compiler stop allowing the pattern? Are there any other traits affected in std?

but wanted to at least open a PR with the change to discuss.

Is this waiting on review then? What specifically is being sought for discussion here?

(Maybe this will become clear once @jackh726 gets an opportunity to write up a summary of the discussion on the linked issue?)

@clarfonthey

clarfonthey commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Yes, apologies for assigning this to you; it should really be:

@rustbot label -T-libs +T-types
r? types

@rustbot rustbot removed the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 13, 2026
@rustbot rustbot assigned Darksonn and unassigned Mark-Simulacrum Sep 13, 2026
@clarfonthey

This comment was marked as outdated.

@rustbot rustbot assigned jhpratt and unassigned Darksonn Sep 13, 2026
@clarfonthey

This comment was marked as outdated.

@rustbot rustbot assigned oli-obk and jackh726 and unassigned jhpratt and oli-obk Sep 13, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor Author

Apologies for this @-mentioning so many people. Will bother more people in the nominated thread as needed.

@clarfonthey clarfonthey added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 13, 2026
@clarfonthey
clarfonthey force-pushed the min-specialization-const branch from 1e20ed2 to 62e4453 Compare September 16, 2026 17:50
@rustbot

rustbot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] build_script_build test:false 0.318
error[E0277]: pointers cannot be reliably compared during const eval
   --> library/core/src/slice/cmp.rs:257:24
    |
255 | / macro_rules! always_applicable_ord {
256 | |     ($([$($p:tt)*] $t:ty,)*) => {
257 | |         $(impl<$($p)*> AlwaysApplicableOrd for $t {})*
    | |                        ^^^^^^^^^^^^^^^^^^^
258 | |     }
259 | | }
    | |_- in this expansion of `always_applicable_ord!`
260 |
261 | / always_applicable_ord! {
262 | |     [] u8, [] u16, [] u32, [] u64, [] u128, [] usize,
263 | |     [] i8, [] i16, [] i32, [] i64, [] i128, [] isize,
264 | |     [] bool, [] char,
...   |
268 | |     [T: AlwaysApplicableOrd] Option<T>,
269 | | }
    | |_- in this macro invocation
    |
    = note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
note: required by a bound in `AlwaysApplicableOrd`
---

error[E0277]: the trait bound `*const T: const SliceOrd` is not satisfied
   --> library/core/src/slice/cmp.rs:257:24
    |
255 | / macro_rules! always_applicable_ord {
256 | |     ($([$($p:tt)*] $t:ty,)*) => {
257 | |         $(impl<$($p)*> AlwaysApplicableOrd for $t {})*
    | |                        ^^^^^^^^^^^^^^^^^^^
258 | |     }
259 | | }
    | |_- in this expansion of `always_applicable_ord!`
260 |
261 | / always_applicable_ord! {
262 | |     [] u8, [] u16, [] u32, [] u64, [] u128, [] usize,
263 | |     [] i8, [] i16, [] i32, [] i64, [] i128, [] isize,
264 | |     [] bool, [] char,
...   |
268 | |     [T: AlwaysApplicableOrd] Option<T>,
269 | | }
    | |_- in this macro invocation
    |
note: required by a bound in `AlwaysApplicableOrd`
   --> library/core/src/slice/cmp.rs:253:34
    |
253 | const trait AlwaysApplicableOrd: const SliceOrd + const Ord {}
    |                                  ^^^^^^^^^^^^^^ required by this bound in `AlwaysApplicableOrd`

error[E0277]: the trait bound `*mut T: const SliceOrd` is not satisfied
   --> library/core/src/slice/cmp.rs:257:24
    |
255 | / macro_rules! always_applicable_ord {
256 | |     ($([$($p:tt)*] $t:ty,)*) => {
257 | |         $(impl<$($p)*> AlwaysApplicableOrd for $t {})*
    | |                        ^^^^^^^^^^^^^^^^^^^
258 | |     }
259 | | }
    | |_- in this expansion of `always_applicable_ord!`
260 |
261 | / always_applicable_ord! {
262 | |     [] u8, [] u16, [] u32, [] u64, [] u128, [] usize,
263 | |     [] i8, [] i16, [] i32, [] i64, [] i128, [] isize,
264 | |     [] bool, [] char,
...   |
268 | |     [T: AlwaysApplicableOrd] Option<T>,
269 | | }
    | |_- in this macro invocation
    |
note: required by a bound in `AlwaysApplicableOrd`
   --> library/core/src/slice/cmp.rs:253:34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants