Wrong translation for iterator into moved container
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 names no source files or tests, so start by locating how the translator maps C++ std::vector iterators to Rust, which the issue describes as a Value<Vec<T>> wrapper with Weak pointers. Reproduce the moved-container case with the snippet in the issue to confirm the mismatch. Settling the design (the costly Value<Value<Vec<T>>> option or a different invalidation rule) needs maintainer input before any patch.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
std::vector<int> src{1, 2, 3};
std::vector<int> dst;
auto it = src.begin(); // (1) iterator to src's first element
dst = std::move(src); // (2) dst steals src's heap buffer; src is left empty
assert(&*it == &dst[0]); // (3) C++: true, the element never moved, dst owns it now
let src: Value<Vec<i32>> = Rc::new(RefCell::new(vec![1, 2, 3])); // Value<T> = Rc<RefCell<T>>
let dst: Value<Vec<i32>> = Rc::new(RefCell::new(Vec::new()));
let it = src.as_pointer().begin(); // (1) Ptr = (Weak to src's Rc, index 0)
dst.write(std::mem::take(&mut *src.borrow_mut()));
// (2) the Vec moves into dst's Rc; src's Rc keeps an empty Vec;
// `it` still refers to src's Rc
assert!(it.deref() == dst[0]); // (3) panics: index 0 out of bounds of the empty Vec in src
In C++ the iterator for vector (or other sequential container) stays valid after src is moved because it points into the same buffer. In Rust the iterator is a Weak reference into the src Value<Vec<T>>. It still points into src after the move.
I think the correct solution is to translate vector as Value<Value<Vec<T>> but this is too costly. Also I am not sure if the behavior in C++ is standard behavior or implementation behavior. I found no explicit sentence in the standard that enforces this.
- Lingua principale
- Rust
- Stelle
- 310
- Fork
- 18
- Merge medio
- 10h 18m
- PR unite (30g)
- 125
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 79/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 Mezza giornata Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 1-2 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Cpp2Rust/cpp2rust
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NSPG13/agent-bounties#1749 ·
I maintainer di solito rispondono entro 1 giorno
-
area: web bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
kinqsradio/orbyn-engineering#227 ·
I maintainer di solito rispondono entro 1 giorno
-
agentic-workflows automation repo-assist
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
shanselman/winget-tui#483 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
lightonai/next-plaid#205 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
apache/datafusion-iceberg#100 ·
I maintainer di solito rispondono entro 1 giorno