References get pointer semantics In rules
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 15/100
Direzione di ricerca
The issue proposes splitting the translation of C++ pointers and references into separate Rust types (Ptr, LvalueRef, RvalueRef) so that rules and STL types like std::pair<int&, int> get correct semantics. Start from the examples in the issue, then find where the translator currently maps both T* and T& to Ptr<T>. Done means the assignment and reference-collapsing examples behave as C++ does, and the design is agreed in the thread.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Both T& and T* are translated as Ptr<T>. When a rule is applied on a reference, the rule sees a Ptr<T> and applies pointer semantics on it.
int x = 1, y = 2;
std::pair<int&, int> a{x, 0}, b{y, 0};
// C++: ✅ assigns through a.first, x == 2
// Translated: ❌ a.first now points to y, x == 1
a = b;
a = std::move(b); // same
std::pair<int&, int> and std::pair<int*, int> are the same translated type so no rule can give them different semantics. Same happens for any STL type that can hold references.
I think that the complete solution is to translate pointers and references as:
T*->Ptr<T>T&->LvalueRef<T>T&&->RvalueRef<T>
All share the layout of Ptr: PtrKind + offset, but the operations differ:
std::pair<int*, int> a(&x, 0), b(&y, 0);
a = b; // T1 = Ptr<i32>: copy_assign copies the address; a.first points to y
std::pair<int&, int> c(x, 0), d(y, 0);
c = d; // T1 = LvalueRef<i32>: copy_assign writes y's value into x; c.first still refers to x
c == d; // LvalueRef<i32>'s == compares x and y, not their addresses
The distinction between Ptr<T>, LvalueRef<T> and RvalueRef<T> is also relevant for reference collapsing which master gets wrong:
int x = 1;
std::pair<int&, int> a(x, 0);
// C++: ✅ writes x, prints x=7
// Translated: ❌ does not compile, std::get<0>(a) is Ptr<Ptr<i32>> instead of Ptr<i32>
std::get<0>(a) = 7;
std::printf("x=%d\n", x);
The reference collapsing rules would be encoded as:
LvalueRef<LvalueRef<T>> => LvalueRef<T> // T& & -> T&
RvalueRef<LvalueRef<T>> => LvalueRef<T> // T& && -> T&
LvalueRef<RvalueRef<T>> => LvalueRef<T> // T&& & -> T&
RvalueRef<RvalueRef<T>> => RvalueRef<T> // T&& && -> T&&
- 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Cpp2Rust/cpp2rust
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
Cpp2Rust/cpp2rust#610 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 22/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
Cpp2Rust/cpp2rust#674 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Cpp2Rust/cpp2rust
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
kashsuks/Pinel#172 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 69/100
I maintainer di solito rispondono entro 1 giorno
-
test_a_503_raises_unavailable_error fails on macOS about one run in sixForse già presa @naman-modi l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
userFRM/egui-charts#4168 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno