docs: size_of
is implemented as stride, but claims otherwise
#33266
Labels
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Discussion of rust-lang/rfcs#1397 with the lang team led to inspection of the documentation for
std::mem::size_of
andstd::intrinsics::size_of
std::mem::size_of
(link) just says "returns the size of a type in bytes." Understanding what this means (and deciding whether it is true or not) depends on how one interprets the word "size" in that sentence.std::intrinsics::size_of
(link) is worse. Why? Because it adds the additional paragraph:This is much more specific, but the added specifics are wrong in terms of that the implementation does.
The quoted text is describing the notion of "size" as denoted by Swift. But Rust's implementation of
std::intrinsics::size_of
ends up eventually calling out to LLVM'sgetTypeAllocSize
, which:At this point we cannot change the name nor the behavior of
std::mem::size_of
-- which is fine, since as I understand it, the behavior ofstd::mem::size_of
basically matches that ofsizeof(T)
in the C/C++ language family.But we should:
std::mem::size_of
, to make it clear what its behavior is (for this, we might as well point out that it is behaving like "stride" in Swift's terms)std::intrinsics::size_of
so it no longer outright lies, or replace that single intrinsic with a pair of intrinsics that are analogous to Swift'ssize
andstride
.Neither of the above items are incredibly high priority, since the
std::mem::size_of
docs are not currently lying (just vague), andstd::intrinsic::size_of
is unstable. But it would probably be good to address at least one of the two, for these reasons:std::mem::size_of
's behavior (and thus manually rounding up its results to each type's alignment), andstd::intrinsic::size_of
docs over intostd::mem::size_of
.The text was updated successfully, but these errors were encountered: