Wrong translation for iterator into moved container
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 15/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Rust
- Estrelas
- 310
- Forks
- 18
- Merge médio
- 10h 18min
- PRs com merge (30d)
- 125
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de Cpp2Rust/cpp2rust
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 79/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 Meio dia Facilidade para iniciantes 55/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 56/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 1-2 dias Facilidade para iniciantes 35/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 56/100
Mantenedores costumam responder em até 1 dia
Todas as issues de Cpp2Rust/cpp2rust
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
fritzprix/libr-agent#2612 ·
Mantenedores costumam responder em até 1 dia
-
crate: spate-core priority: low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
NSPG13/agent-bounties#1749 ·
Mantenedores costumam responder em até 1 dia
-
area: web bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
kinqsradio/orbyn-engineering#227 ·
Mantenedores costumam responder em até 1 dia
-
移动端下载页实时吞吐与筛选栏滚动层级不一致Abertaenhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia