Conversation
|
At the current state of this PR, I've more questions than I have content, so consider this more like an issue than a PR at the moment. The wording in I don't like the usage of Are there any other structs that we guarantee the size for? |
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
small nit: Option<&UT>
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
While you're here, consider mentioning that this is "successive elements in an array with that item type", since layout optimization can (in theory at least) change the layout of "successive items of the same type" in a struct.
src/libstd/primitive_docs.rs
Outdated
There was a problem hiding this comment.
nit: "one byte" here distracted me, though perhaps only in context of reviewing something about sizes. Perhaps a phrasing like "to reference any location in memory"?
There was a problem hiding this comment.
If I change it to this, I have to also describe what a location in memory is, no?
There was a problem hiding this comment.
Hmm, *T::offset talks of "allocated object", so maybe use that instead of location? Though I don't know if it's defined anywhere (other than LLVM) either...
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
Perhaps mention that it's always a multiple of align_of::<T>(), as well?
There was a problem hiding this comment.
I don't know what you mean by this.
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
I think the accepted extern types RFC means that there will exist types that are not Sized but are none-the-less thin pointers. And there has been discussion of extra-fat pointers for things like dyn (Debug + Add). So it might be better to not mention this particularly, especially since use cases for relying on it are kinda sketchy.
There was a problem hiding this comment.
So basically the size of &T is generally unstable?
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
Should probably have *const T and *mut T as well.
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
[00:03:45] tidy error: /checkout/src/libcore/mem.rs:182: trailing whitespace
There was a problem hiding this comment.
and size_of::<T>() here as well
|
@rust-lang/libs, are you okay with what we are guaranteeing stable here? |
|
They seem reasonable to me. |
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
Typo.
assert_eq!(8, mem::size_of::<f64)());
// ^ should be `>`There was a problem hiding this comment.
As kennytm wrote, there is a typo after f64.
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
Could we say "are" instead of "will be", and "has"/"have" instead of "will have" above? The rest of this documentation is written in present tense so "will" makes it seem like those features are not implemented yet.
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
I found this a little hard to parse. A skeptical reader would read this as:
Options &T
\ /
of Box<T>
\ /
and the pointer
\ /
have the same size as
instead of
&T Box<T>
\ /
Options and
\ /
of the pointer
\ /
have the same size as
because that sounds more plausible to someone skeptical of zero overhead abstractions.
Is there a way to word this that shows the full types Option<&T> and Option<Box<T>> in the sentence?
Maybe something straightforward like:
The types *T, &T, Box<T>, Option<&T>, and Option<Box<T>> all have the same size. If T is Sized, all of those have the same size as usize.
There was a problem hiding this comment.
Yeah, I was sort of floundering with that section. That reads a lot better.
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
As durka wrote, this would be clearer as size_of::<Type>() instead of size_of<Type>().
There was a problem hiding this comment.
Also I believe these need to be in backticks or escaped with a backslash. Otherwise markdown will treat it as a <Type> HTML tag.
`Type` | `size_of::<Type>()`
Type | size_of::\<Type>()
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
This might be the first place we say *T instead of *const T/*mut T? Likewise, everything here about &T applies to &mut T.
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
error: expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)
src/libcore/mem.rs
Outdated
|
One more type we guarantee is |
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
; to separate i32 from the length.
There was a problem hiding this comment.
I thought I was running the doctests; I actually wasn't.
|
All nits should be fixed. I don't have dtolnay's thing here. I'm wondering if the null pointer optimization for Option-shaped enums is actually stable, and if so, we could just say that, and then point out what the common nullable pointer types are, including I'm avoiding talking about I can also squash all the commits into one if you want. |
|
I like what you have here; the Details about enum size is probably mixed up in #27730 & rust-lang/rfcs#1230, and fine to leave for later. |
src/libcore/mem.rs
Outdated
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
As durka wrote, this would be clearer as size_of::<Type>() instead of size_of<Type>().
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
The rest of this documentation is in present tense so "will have" makes it sound like this part is not implemented yet. Plain "have" should be sufficient I think.
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
As kennytm wrote, there is a typo after f64.
src/libcore/mem.rs
Outdated
There was a problem hiding this comment.
This should say [i32; 3] instead of [i32, 3].
|
r=me after the last few typos are addressed. I agree we don't need to include |
|
Finally figured out how to get rustdoc tests to compile for this. Items in libstd from the libcore facade don't actually get tested from Also rebased everything into a single commit to avoid polluting the commit log with typo fixing and whatnot. |
|
@bors r+ |
|
📌 Commit 548686f has been approved by |
|
@bors rollup |
Expand size_of docs This PR does 3 things. 1. Adds a description of what pointer size means to the primitive pages for usize and isize. 2. Says the general size of things is not stable from compiler to compiler. 3. Adds a table of sizes of things that we do guarantee. As this is the first table in the libstd docs, I've included a picture of how that looks. 
Expand size_of docs This PR does 3 things. 1. Adds a description of what pointer size means to the primitive pages for usize and isize. 2. Says the general size of things is not stable from compiler to compiler. 3. Adds a table of sizes of things that we do guarantee. As this is the first table in the libstd docs, I've included a picture of how that looks. 
This PR does 3 things.