Spaceship operator always returns strong_ordering

Aperta
#677 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp, rust
Ambito
compilers

Direzione di ricerca

The spaceship operator is currently lowered to Ord::cmp in the C++-to-Rust translation pass, so start by finding where binary <=> is handled in the Clang AST visitor and the matching Rust emission code. The issue asks for a ThreeWayComparable-style trait so the result category follows the operand types, including partial_ordering for floats and the weakest-member rule for std::pair. Done means 1.0 <=> 2.0 and pair{NAN, 1} < pair{NAN, 2} translate with the correct ordering semantics and have tests covering them.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

a <=> b is translated as Ord::cmp, which always gives Ordering (strong_ordering). In C++ the result depends on the operands:

1 <=> 2        // strong_ordering
1.0 <=> NAN    // partial_ordering (unordered)
w1 <=> w2      // weak_ordering, if W's operator<=> returns it

So 1.0 <=> 2.0 does not compile, and a weak ordering becomes strong.

std::pair's operator<=> returns the weakest category of its members (pair<double, int> gives partial_ordering). Its rule is generic, so without a trait for <=> it can only compare the members with < and return Ordering, and pair{NAN, 1} < pair{NAN, 2} is true instead of false.

We need to translate spaceship operator to a ThreeWayComparable trait.

Lingua principale
Rust
Stelle
310
Fork
18
Merge medio
9h 46m
PR unite (30g)
82

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Cpp2Rust/cpp2rust

Tutte le issue di Cpp2Rust/cpp2rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.