-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Docs: slice elements are equidistant #64703
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @rkruppe (rust_highfive has picked a reviewer for you, use r? to override) |
I understood this from the word "contiguous". Maybe instead of introducing a new word ("equidistantly"), it might be more helpful to explain in the body what contiguous means, e.g.,
but maybe trying to word that in a beginner-friendly way. |
"constant stride" is the word used in the Unsafe Code Guidelines. (Also, it's possible that |
4fc66db
to
156f686
Compare
I am not a fan of the UCG trying to accommodate hypothetical future "stride != size" changes (see discussion in rust-lang/unsafe-code-guidelines#176) so I'm not thrilled to see it make its way into some[1] libstd docs. Can we make the intended clarification without opening this can of worms? Perhaps something like @gnzlbg propoed earlier, but avoid mentioning
|
That part of that page of the UCGs is non-normative and quite controversial
so it will probably be removed as soon as someone sends a PR for it.
Beyond what @rkruppe said, putting anything about that page into the docs
would require Lang team approval because it introduces the concept of a
stride in Rust, which AFAIK is not mentioned anywhere else.
|
156f686
to
6ccb7ae
Compare
Ok, I removed the "stride" part as per @rkruppe's request. r? |
Thanks! @bors r+ rollup |
📌 Commit 6ccb7ae has been approved by |
Thanks @rkruppe! |
src/libstd/primitive_docs.rs
Outdated
@@ -566,7 +566,9 @@ mod prim_array { } | |||
#[doc(alias = "[")] | |||
#[doc(alias = "]")] | |||
#[doc(alias = "[]")] | |||
/// A dynamically-sized view into a contiguous sequence, `[T]`. | |||
/// A dynamically-sized view into a contiguous sequence, `[T]`. Contiguous here | |||
/// means that elements are layed out so that every element is the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/layed out/laid out/
Had to look this one up myself: https://writingexplained.org/laid-out-or-layed-out
…, r=rkruppe Docs: slice elements are equidistant Recently, someone asked why `[char]` and `str` are not interchangeable, and I explained that in a slice, the elements must be laid out equidistantly, whereas the chars in a `str` are stored compactly regardless their size. However I couldn't find this documented anywhere, so here's a small addition of this fact.
Rollup of 14 pull requests Successful merges: - #63492 (Remove redundancy from the implementation of C variadics.) - #64703 (Docs: slice elements are equidistant) - #64745 (Include message on tests that should panic but do not) - #64781 (Remove stray references to the old global tcx) - #64794 (Remove unused DepTrackingMap) - #64802 (Account for tail expressions when pointing at return type) - #64809 (hir: Disallow `target_feature` on constants) - #64815 (Fix div_duration() marked as stable by mistake) - #64818 (update rtpSpawn's parameters type(It's prototype has been updated in libc)) - #64830 (Thou shallt not `.abort_if_errors()`) - #64836 (Stabilize map_get_key_value feature) - #64845 (pin.rs: fix links to primitives in documentation) - #64847 (Upgrade env_logger to 0.7) - #64851 (Add mailmap entry for Dustin Bensing by request) Failed merges: - #64824 (No StableHasherResult everywhere) r? @ghost
…, r=rkruppe Docs: slice elements are equidistant Recently, someone asked why `[char]` and `str` are not interchangeable, and I explained that in a slice, the elements must be laid out equidistantly, whereas the chars in a `str` are stored compactly regardless their size. However I couldn't find this documented anywhere, so here's a small addition of this fact.
Rollup of 14 pull requests Successful merges: - #64703 (Docs: slice elements are equidistant) - #64745 (Include message on tests that should panic but do not) - #64781 (Remove stray references to the old global tcx) - #64794 (Remove unused DepTrackingMap) - #64802 (Account for tail expressions when pointing at return type) - #64809 (hir: Disallow `target_feature` on constants) - #64815 (Fix div_duration() marked as stable by mistake) - #64818 (update rtpSpawn's parameters type(It's prototype has been updated in libc)) - #64830 (Thou shallt not `.abort_if_errors()`) - #64836 (Stabilize map_get_key_value feature) - #64845 (pin.rs: fix links to primitives in documentation) - #64847 (Upgrade env_logger to 0.7) - #64851 (Add mailmap entry for Dustin Bensing by request) - #64859 (check_match: improve diagnostics for `let A = 2;` with `const A: i32 = 3`) Failed merges: r? @ghost
6ccb7ae
to
410ce86
Compare
Thanks @petertodd for the correction! @rkruppe can you reapprove? Sorry @Centril if this interferes with your roll-up. |
(Noted also on Discord): Force pushing to a PR in a rollup has no effect on the rollup (which should not be cancelled unless there's a serious problem in the PR (a typo does not qualify)). You will need to rebase atop upstream-master after the rollup has been merged. |
☔ The latest upstream changes (presumably #64864) made this pull request unmergeable. Please resolve the merge conflicts. |
Slice docs: fix typo With rust-lang#64703, I introduced a typo. Here is the fix. Sorry for the inconvenience.
Recently, someone asked why
[char]
andstr
are not interchangeable, and I explained that in a slice, the elements must be laid out equidistantly, whereas the chars in astr
are stored compactly regardless their size. However I couldn't find this documented anywhere, so here's a small addition of this fact.