2 ms·
Genuinely asking: what about this is different from what I said in the original comment? It's possible that I'm using the wrong words, but my understanding of R
by woodruffw 4y ago
Genuinely asking: what about this is different from what I said in the original comment? It's possible that I'm using the wrong words, but my understanding of Rust's ownership semantics is that "owns a reference" and "borrows the underlying value" are equivalent statements.
- cormacrelf 4y agoYou can have a PhantomData without a bar field. You could have baz and qux fields as well. The compiler does not know the lifetime in the phantom data is connected to any other field whatsoever. It doesn’t look through the other fields searching for *const T. It’s just a lifetime and is connected to T, not any particular pointer to T. The bar field happens to have a T in it, so the T: 'a constraint does apply to what you store inside the pointer, but the *const T is lifetime-erased as it relates to the pointer, so you have to ensure that the lifetime of the *const T matches up with the lifetime your Foo type claims it has (in its documentation). You must do that manually by constraining the struct creation and field access. You would also typically have a safe method to turn bar back into a borrow in some way (like IterMut::next does) and when you do, you will want to be sure that the pointer is actually valid for the lifetime you say it is.*
- woodruffw 4y agoThanks for the explanation! I can see how my nitpick wasn't right then, either. I'm going to make an edit noting that.