Rust-GPU / Rust-GPU/rust-gpu

`PartialOrd` doesn't work with new type

Offen
#409 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Rust
Sterne
3.4k
Forks
125
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I have the following trivial new type:

#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, From, Into)]
pub struct CustomPosition(u32);

When trying to compare two values of this type, I'm getting an error:

  error: `i8` type used without `OpCapability Int8`
       |
  note: used from within `<u32 as core::cmp::PartialOrd>::partial_cmp`
      --> /home/nazar-pc/.rustup/toolchains/nightly-2025-06-23-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cmp.rs:1989:5
       |
  1989 |     ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  note: called by `<ab_proof_of_space_gpu::shader::sort_buckets::CustomPosition as core::cmp::PartialOrd>::partial_cmp`
      --> crates/farmer/ab-proof-of-space-gpu/src/shader/sort_buckets.rs:17:35
       |
  17   | #[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, From, Into)]
       |                                   ^^^^^^^^^^
  note: called by `<ab_proof_of_space_gpu::shader::sort_buckets::CustomPosition as core::cmp::PartialOrd>::le`
      --> /home/nazar-pc/.rustup/toolchains/nightly-2025-06-23-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cmp.rs:1403:14
       |
  1403 |         self.partial_cmp(other).is_some_and(Ordering::is_le)
       |              ^^^^^^^^^^^^^^^^^^
  note: called by `ab_proof_of_space_gpu::shader::sort_buckets::perform_compare_swap`
      --> crates/farmer/ab-proof-of-space-gpu/src/shader/sort_buckets.rs:80:32
       |
  80   |     let (smaller, larger) = if a <= b { (a, b) } else { (b, a) };
       |                                ^^^^^^

At the same time, comparison of u32 directly works fine and doesn't require Int8 capability.

While this is likely related to discussion in https://github.com/Rust-GPU/rust-gpu/issues/307, I think it is distinct enough to be reported separately.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Reproduktion in crates/farmer/ab-proof-of-space-gpu/src/shader/sort_buckets.rs, insbesondere mit dem CustomPosition derive in Zeile 17 und dem Vergleich in Zeile 80. Vergleiche den generierten PartialOrd-Pfad für CustomPosition mit dem direkten u32-Vergleich und untersuche anschließend die Behandlung der unerwünschten Int8-Fähigkeit; als erledigt gilt dies, wenn Newtype-Vergleiche kompiliert werden, ohne Int8 zu erfordern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.