References get pointer semantics In rules
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 15/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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&&
- Vorherrschende Sprache
- Rust
- Sterne
- 310
- Forks
- 18
- Ø Merge
- 9 Std. 46 Min.
- Gemergte PRs (30 T.)
- 82
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus Cpp2Rust/cpp2rust
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
Cpp2Rust/cpp2rust#610 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 22/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
Cpp2Rust/cpp2rust#674 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in Cpp2Rust/cpp2rust
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
kashsuks/Pinel#172 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 69/100
Maintainer antworten meist innerhalb von 1 Tag
-
test_a_503_raises_unavailable_error fails on macOS about one run in sixEvtl. vergeben @naman-modi hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug ui
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
userFRM/egui-charts#4168 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 1 Tag