-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add primitive doc for () #15321
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
Add primitive doc for () #15321
Conversation
Quick poll on IRC suggested that unit was the preferred name for ().
//! fn long() -> () {} | ||
//! | ||
//! fn short() {} | ||
//! ``` |
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.
Maybe mention ;
too?
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.
Added a paragraph below; what do you think?
This would make for the second public-facing, documentation-only module (other one being I would prefer to have these both not be publicly usable modules and only accessible from the documentation, but alas! I need to go and write some more rustdoc logic! |
|
||
#![doc(primitive = "unit")] | ||
|
||
//! The `()` type, sometimes called "nil" or "unit". |
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.
Perhaps invert the mention of nil/unit? (just to emphasize that unit is the conventional naming).
r=me with or without the two comments above, thanks! |
//! fn short() {} | ||
//! ``` | ||
//! | ||
//! The semicolon `;` can be used to discard a result of statement at |
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.
It's the result of an expression, not a statement.
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.
(1;)
is not valid, i.e. a ;
'd expression has to be in statement position.
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.
Ahhh I see what you're saying. Also, the phrasing is awkward, should probably be "can be used to discard the result of a statement at".
What I was thinking of was that ; discards the results of the 1, which is an expression, and gives () instead.
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.
Oh, yes, the phrasing is horrible. I edited two sentences into one without actually making them connect properly...
Yeah, that's a good point, I think saying "end of some block" specifically is enough to change statement to expression, so I'll do that.
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.
Updated. Is this better?
This adds a primitive page for () like http://doc.rust-lang.org/master/std/uint/primitive.uint.html . I would prefer the modules to be `std::tuple::unit`, but rustdoc only searches at the top level (filed as #15320).
//! | ||
//! The semicolon `;` can be used to discard the result of an | ||
//! expression at the end of a block, making the expression (and thus | ||
//! the block) evaluate to `()`. For example, |
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.
I've been using For example:
rather than For example,
, I wonder which is better?
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.
Oh, don't know.
(It's mainly just a habit I have from mathematics, where even an "broken out" equation is normally written to be a natural part of the sentence it's in
Hence, we've proven that
a + 2 = 3
where
a = 1
.
This may not be the style we want for Rust's docs.)
Normalize expected ty in call arguments fix rust-lang#15321 I'm not sure if we should do this, or add a normalize in the beginning of `infer_expr_inner`, or somewhere else. r? `@lowr`
This adds a primitive page for () like http://doc.rust-lang.org/master/std/uint/primitive.uint.html .
I would prefer the modules to be
std::tuple::unit
, but rustdoc only searches at the top level (filed as #15320).