rust-lang / nomicon

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

Fix opaque type representation. #257

Closed skade closed 3 years ago

skade commented 3 years ago

Fix for #250.

Final pattern derived by @nvzqz, with help from @dtolnay.

thomcc commented 3 years ago

That pattern was actually fine though, wasn't it?

Since you never use Bar by value, you use it behind a raw pointer, which is thus !Send, !Sync, and Pinning wouldn't apply.

I think a bigger (and possibly more controversial) issue is not discouraging using these types by value/reference, which is likely UB under the current aliasing semantics (although it is a thing people do...)

As it is, I've seen people confused about the reasoning here, and IDK if this change makes things clearer.