-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs for never primitive #46232
Add docs for never primitive #46232
Conversation
src/libstd/primitive_docs.rs
Outdated
/// [`Debug`]: fmt/trait.Debug.html | ||
/// [`Default`]: default/trait.Default.html | ||
/// | ||
#[stable(feature = "rust1", since = "1.23.0")] |
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.
Should this be attached to rust1
, or would it be attached to never_type
? I would assume the latter.
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.
That's also the reason why tidy errors:
[00:03:19] tidy error: /checkout/src/libstd/primitive_docs.rs:171: mismatches to previous in: ["since"]
[00:03:19] tidy error: /checkout/src/libstd/primitive_docs.rs:247: mismatches to previous in: ["since"]
because rust1 has been defined elsewhere already (probably with a since field of "1.0.0") and the since field that @canndrew specified "1.23.0" mismatches.
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 changed it to #[unstable(feature = "never_type_impls", issue = "35121")]
since that's what's used in other places in libstd/libcore.
The following doc tests failed:
|
Is there a way to run doc tests separately? Also, I just forced-pushed an amendment to that last commit but it didn't cancel the old travis job. So job #63107 can be cancelled (would be nice if it happened automatically though). |
Out of curiosity, is it possible to reuse the |
I don't know what headaches it would cause but I remember that there was a reason for having a separate |
You can use one single feature gate for lib and language features. See #43089 |
The unstable book handles them not really well. Documentation for the Maybe it would be an idea to create a "common feature" list. |
Looks good, but i have one request: Can you change this line here to |
@rust-lang/docs Any comments on the doc text here? I think it's good, but it would be nice to have more eyes on it. |
@@ -67,6 +67,123 @@ | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
mod prim_bool { } | |||
|
|||
#[doc(primitive = "never")] | |||
// |
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.
Why this line?
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'm not sure why it was there in the first place, but it does match the other primitive docs.
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.
We should remove them then!
@rust-lang/cleanup-team
@@ -67,6 +67,123 @@ | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
mod prim_bool { } | |||
|
|||
#[doc(primitive = "never")] | |||
// | |||
/// The `!` type, also called "never". |
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.
This "introduction" sounds strange. I expected to have something after directly but just a dot. So strange.
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.
This kind of introduction line matches the other primitives. Compare with "Raw, unsafe pointers, *const T
, and *mut T
", "References, both shared and mutable", "A finite heterogeneous sequence, (T, U, ..)
", all of which appear in the current docs. Do you have a better suggestion?
src/libstd/primitive_docs.rs
Outdated
/// so returns `!`. | ||
/// | ||
/// `break`, `continue` and `return` expressions also have type `!`. For example we are allowed to | ||
/// write |
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.
Please add :
.
src/libstd/primitive_docs.rs
Outdated
/// } | ||
/// ``` | ||
/// | ||
/// When implementing this trait for `String` we need to pick a type for `Err`. And since |
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.
Please add urls for String
and Err
.
src/libstd/primitive_docs.rs
Outdated
/// let Ok(s) = String::from_str("hello"); | ||
/// ``` | ||
/// | ||
/// Since the `Err` variant contains a `!`, it can never occur. So we can exhaustively match on |
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.
URL for Err
.
src/libstd/primitive_docs.rs
Outdated
/// ``` | ||
/// | ||
/// Since the `Err` variant contains a `!`, it can never occur. So we can exhaustively match on | ||
/// `Result<T, !>` by just taking the `Ok` variant. This illustrates another behaviour of `!` - it |
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.
URLs for Result
and Ok
.
src/libstd/primitive_docs.rs
Outdated
/// # } | ||
/// ``` | ||
/// | ||
/// Both match arms must produce values of type `u32`, but since `break` never produces a value 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.
URL for u32
.
src/libstd/primitive_docs.rs
Outdated
/// ``` | ||
/// | ||
/// Both match arms must produce values of type `u32`, but since `break` never produces a value at | ||
/// all we know it can never produce a value which isn't a `u32`. This illustrates another |
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.
URL for u32
.
src/libstd/primitive_docs.rs
Outdated
/// When implementing this trait for `String` we need to pick a type for `Err`. And since | ||
/// converting a string into a string will never result in an error, the appropriate type is `!`. | ||
/// (Currently the type actually used is an enum with no variants, though this is only because `!` | ||
/// was added to Rust at a later date and it may change in the future). With an `Err` type of `!`, |
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.
URL for Err
.
src/libstd/primitive_docs.rs
Outdated
/// converting a string into a string will never result in an error, the appropriate type is `!`. | ||
/// (Currently the type actually used is an enum with no variants, though this is only because `!` | ||
/// was added to Rust at a later date and it may change in the future). With an `Err` type of `!`, | ||
/// if we have to call `String::from_str` for some reason the result will be a `Result<String, !>` |
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.
URLs for String::from_str
, Result
and String
.
src/libstd/primitive_docs.rs
Outdated
/// } | ||
/// ``` | ||
/// | ||
/// Once again we're using `!`'s ability to coerce into any other type, in this case `fmt::Result`. |
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.
URL for fmt::Result
.
src/libstd/primitive_docs.rs
Outdated
/// Since this method takes a `&!` as an argument we know that it can never be called (because | ||
/// there is no value of type `!` for it to be called with). Writing `*self` essentially tells the | ||
/// compiler "We know that this code can never be run, so just treat the entire function body has | ||
/// having type `fmt::Result`". This pattern can be used a lot when implementing traits for `!`. |
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.
URL for fmt::Result
.
src/libstd/primitive_docs.rs
Outdated
/// | ||
/// Since `!` has no values, it has no default value either. It's true that we could write an | ||
/// `impl` for this which simply panics, but the same is true for any type (we could `impl | ||
/// Default` for (eg.) `File` by just making `default()` panic.) |
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.
URLs for File
and default()
.
Text seems good to me (at one exception). However a lot of small nits. :) |
Thanks for the feedback. I've added all those missing links. |
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.
Sorry for letting this get stale! I looked over the docs again and i have a couple nits. Once these are settled we can go ahead and merge it!
/// let x: ! = { | ||
/// return 123 | ||
/// }; | ||
/// # } |
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 feel like we should show the feature flag here, since it's needed to give x
the proper type.
src/libstd/primitive_docs.rs
Outdated
/// [`Result<String, !>`] which we can unpack like this: | ||
/// | ||
/// ```ignore (string-from-str-error-type-is-not-never-yet) | ||
/// let Ok(s) = String::from_str("hello"); |
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 know these ignore
blocks get a little info tooltip and callout border now, but i'd prefer it if we had a comment in here along the lines of "NOTE: This does not work today!", just to sate my paranoia about people blindly copy/pasting examples from docs.
Heads up from triage @canndrew — you've got some pending feedback to address! |
Thanks for the reminder! I've pushed a couple of small fixes. |
Thanks so much! @bors r+ |
📌 Commit 172f16b has been approved by |
Add docs for never primitive cc @nikomatsakis, @QuietMisdreavus
☀️ Test successful - status-appveyor, status-travis |
cc @nikomatsakis, @QuietMisdreavus