rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.75k stars 256 forks source link

Potential error in exception-safety #359

Open Arthur-Milchior opened 2 years ago

Arthur-Milchior commented 2 years ago

In https://doc.rust-lang.org/nomicon/exception-safety.html I suspect that self.ptr().add(i).write(x.clone()); is wrong. i is the position of x in to_push. We don't want to put x at position i as it would overwrite an already existing value. Instead we want it at position i+initial_length. At least I assume. I don't understand how to find the documentation of ptr(), I don't see it in https://doc.rust-lang.org/stable/std/vec/struct.Vec.html . But I can't figure out a semantic off "add" where it makes sens to take "i"