Expand and organize offset_of! documentation.#138323
Conversation
* Give example of how to get the offset of an unsized tail field (prompted by discussion <rust-lang#133055 (comment)>). * Specify the return type. * Add section headings. * Reduce “Visibility is respected…”, to a single sentence.
library/core/src/mem/mod.rs
Outdated
| /// If the nightly-only feature `offset_of_enum` is enabled, | ||
| /// variants may be traversed as if they were fields. | ||
| /// `enum` variants may be traversed as if they were fields. |
There was a problem hiding this comment.
Suggestion: maybe link to the tracking issue?
[`offset_of_enum`]: https://github.com/rust-lang/rust/issues/120141
But also, this is describing the interaction of this stable macro w/ an unstable feature. Maybe move this to a section like
# Interactions with unstable featuresor maybe move this bit to docs for offset_of_enum? 🤔
There was a problem hiding this comment.
I think it's OK in this particular case to reference unstable features, even if we normally don't, since this seems like a natural place for people to look for that functionality. I don't think we have offset_of_enum! (yet?) - not sure what you mean by that.
There was a problem hiding this comment.
Right.
I don't think we have offset_of_enum! (yet?) - not sure what you mean by that.
Not sure why I wrote this lmao.
There was a problem hiding this comment.
I assumed you meant to put the documentation in the unstable book, and I think that makes sense. Should I not?
(Also while writing that documentation, I found a bug-or-design-question: #138327.)
There was a problem hiding this comment.
Right, I think that's what I wanted to say lol
There was a problem hiding this comment.
I think we should at minimum link to those docs, even if we don't have a stable thing to link to - otherwise people will handroll stuff I suspect and we've seen that cause UB, etc. in the past.
There was a problem hiding this comment.
IOW, probably do nothing here :D
There was a problem hiding this comment.
I've now moved all the unstable feature documentation to the unstable book, except for links to it from offset_of, and summaries.
|
@bors r+ |
Rollup of 16 pull requests Successful merges: - rust-lang#133055 (Expand `CloneToUninit` documentation.) - rust-lang#137147 (Add exclude to config.toml) - rust-lang#137864 (Don't drop `Rvalue::WrapUnsafeBinder` during GVN) - rust-lang#137890 (doc: clarify that consume can be called after BufReader::peek) - rust-lang#137956 (Add RTN support to rustdoc) - rust-lang#137968 (Properly escape regexes in Python scripts) - rust-lang#138082 (Remove `#[cfg(not(test))]` gates in `core`) - rust-lang#138275 (expose `is_s390x_feature_detected!` from `std::arch`) - rust-lang#138303 (Fix Ptr inconsistency in {Rc,Arc}) - rust-lang#138309 (Add missing doc for intrinsic (Fix PR135334)) - rust-lang#138323 (Expand and organize `offset_of!` documentation.) - rust-lang#138329 (debug-assert that the size_hint is well-formed in `collect`) - rust-lang#138465 (linkchecker: bump html5ever) - rust-lang#138471 (Clean up some tests in tests/ui) - rust-lang#138472 (Add codegen test for rust-lang#129795) - rust-lang#138484 (Use lit span when suggesting suffix lit cast) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#138323 - kpreid:offset-of-doc, r=Mark-Simulacrum Expand and organize `offset_of!` documentation. * Give example of how to get the offset of an unsized tail field (prompted by discussion <rust-lang#133055 (comment)>). * Specify the return type. * Add section headings. * Reduce “Visibility is respected…”, to a single sentence. * Move `offset_of_enum` documentation to unstable book (with link to it). * Add `offset_of_slice` documentation in unstable book. r? Mark-Simulacrum
…acrum Expand and organize `offset_of!` documentation. * Give example of how to get the offset of an unsized tail field (prompted by discussion <rust-lang#133055 (comment)>). * Specify the return type. * Add section headings. * Reduce “Visibility is respected…”, to a single sentence. * Move `offset_of_enum` documentation to unstable book (with link to it). * Add `offset_of_slice` documentation in unstable book. r? Mark-Simulacrum
CloneToUninitdocumentation. #133055 (comment)).offset_of_enumdocumentation to unstable book (with link to it).offset_of_slicedocumentation in unstable book.r? Mark-Simulacrum