rust-lang / nomicon

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

trivial: if Vec::into_iter() mispelled the comments ? #304

Open laokz opened 3 years ago

laokz commented 3 years ago

https://github.com/rust-lang/nomicon/blob/master/src/vec/vec-into-iter.md#L62

impl<T> Vec<T> {
    pub fn into_iter(self) -> IntoIter<T> {
        // Can't destructure Vec since it's Drop                <=== if 'Drop' should be 'Copy' ?
        let ptr = self.ptr;
        let cap = self.cap;
        let len = self.len;
ehuss commented 3 years ago

Can you say more about what you think is wrong? I think the comment is saying you can't destructure with something like let Vec{ptr, cap, len} = self; because that would drop it, which it explicitly does not want to do.

laokz commented 3 years ago

Thanks for your quick reply!

My poor english & less rust experience misled me :-/ I thought the comment was for let ptr=self.ptr, that self.ptr's type is NonNull which implemented Copy trait, so the statement could not destroy the buffer. My bad, sorry.

laokz commented 3 years ago

By the way, how let Vec{ptr, cap, len} = self would drop it? I tried that self still accessible after this.

ehuss commented 3 years ago

Oh, good point! I don't know what the comment means then. 🙃