Skip to content

rewrite never type documentation#158370

Draft
WaffleLapkin wants to merge 4 commits into
rust-lang:mainfrom
WaffleLapkin:never-scratch-docs
Draft

rewrite never type documentation#158370
WaffleLapkin wants to merge 4 commits into
rust-lang:mainfrom
WaffleLapkin:never-scratch-docs

Conversation

@WaffleLapkin

@WaffleLapkin WaffleLapkin commented Jun 24, 2026

Copy link
Copy Markdown
Member

View all comments

With the never type stabilization approaching, I think the documentation could be improved a lot over the status quo ^^'

I intend to merge this after #155499. Split it off into a separate PR for ease of reviewing.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 24, 2026
@WaffleLapkin WaffleLapkin added the F-never_type `#![feature(never_type)]` label Jun 24, 2026
@WaffleLapkin WaffleLapkin added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2026

@kpreid kpreid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw some typos, so here’s a batch of copyediting suggestions (also some for jargon clarification). Feel free to ignore these if not useful.

View changes since this review

Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
@traviscross traviscross self-assigned this Jun 25, 2026
@traviscross traviscross added T-lang Relevant to the language team T-lang-docs Relevant to the lang-docs team. labels Jun 25, 2026

@mkrasnitski mkrasnitski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the slightly messy diff, I ended up splitting my review up into many small comments, so apologies for the large number of them. Most are copy-edits, with a couple small content changes here and there. Feel free to use them or not as you see fit.

View changes since this review

Comment on lines +67 to +68
/// `!` is the canonical uninhabited type. `!` represents the type of diverging computations --
/// computations which never resolve to any value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// `!` is the canonical uninhabited type. `!` represents the type of diverging computations --
/// computations which never resolve to any value.
/// `!` represents the type of diverging computations -- computations which never resolve to any
/// value. It the canonical uninhabited type.

Comment thread library/core/src/primitive_docs.rs Outdated
Comment on lines +73 to +75
/// For example, the [`exit`] function is defined as returning `!`, to signify that it doesn't
/// return normally and exits the process instead. Thus, any code following a call to [`exit`] is
/// unreachable. ([`panic!`] works the same way.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// For example, the [`exit`] function is defined as returning `!`, to signify that it doesn't
/// return normally and exits the process instead. Thus, any code following a call to [`exit`] is
/// unreachable. ([`panic!`] works the same way.)
/// For example, the [`exit`] function is defined as returning `!`, to signify that it exits the
/// process instead of returning normally. Thus, any code following a call to [`exit`] is
/// unreachable. The [`panic!`] macro works the same way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your suggestion is misleading here. returning ! doesn't signify that the function exits the process, only that it doesn't return. Now realizing, that my version kind-of struggles from the same issue...

How about the following?

For example, the exit function is defined as returning !, to signify that it doesn't return normally (as it exits the process instead).

Comment on lines +77 to +78
/// Similarly, [`return`], [`break`], [`continue`], [`become`], and infinite [`loop`] expressions
/// all have type `!`, as the code following them is unreachable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should become be included here if it is still unstable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs
Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
Comment on lines +283 to +285
/// This is because `impl Trait` is not a specific type in and of itself, but instead a marker that
/// the return type of the function is hidden and the only thing that can be assumed by the caller
/// is that whatever the type is, it implements `Trait`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This is because `impl Trait` is not a specific type in and of itself, but instead a marker that
/// the return type of the function is hidden and the only thing that can be assumed by the caller
/// is that whatever the type is, it implements `Trait`.
/// Here, never-to-any coercion fails because `impl Trait` is not itself a concrete type, but rather
/// a way to tell the compiler that a function's return type is hidden, and the only thing which can
/// be assumed about this type is that it implements `Trait`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never-to-any doesn't fail here; the failure is that the hidden type doesn't implement the correct trait.

I rewrote "a specific type in and of itself" though.

Comment on lines +287 to +288
/// In case of using `todo!()` the hidden return type is inferred to be `!`, which may not
/// implement the trait.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// In case of using `todo!()` the hidden return type is inferred to be `!`, which may not
/// implement the trait.
/// The compiler then attempts to choose such a concrete type, but is unable to do so. In this case,
/// we abandon the coercion and fall back to just the never type itself, which will fail to compile
/// if `!` does not implement `Trait`.

I think fallback should be explicitly mentioned here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler then attempts to choose such a concrete type, but is unable to do so.

This is not true; the compiler chooses ! here.

I think mentioning fallback here only makes it more confusing...

Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
WaffleLapkin and others added 4 commits June 30, 2026 11:06
Co-authored-by: Kevin Reid <kpreid@switchb.org>
Co-authored-by: Kevin Reid <kpreid@switchb.org>
Co-authored-by: Michael Krasnitski <42564254+mkrasnitski@users.noreply.github.com>
Co-authored-by: waffle <waffle.lapkin@gmail.com>
Co-authored-by: Michael Krasnitski <42564254+mkrasnitski@users.noreply.github.com>

@WaffleLapkin WaffleLapkin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkrasnitski thanks for your suggestions!

View changes since this review

Comment thread library/core/src/primitive_docs.rs Outdated
Comment on lines +283 to +285
/// This is because `impl Trait` is not a specific type in and of itself, but instead a marker that
/// the return type of the function is hidden and the only thing that can be assumed by the caller
/// is that whatever the type is, it implements `Trait`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never-to-any doesn't fail here; the failure is that the hidden type doesn't implement the correct trait.

I rewrote "a specific type in and of itself" though.

Comment thread library/core/src/primitive_docs.rs Outdated
Comment on lines +209 to +210
/// At first glance there is no reason to implement any traits for `!`. Most traits take a value
/// of `Self` as an argument in methods, so you won't be able to call them anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorporated this into my last commit.

Comment thread library/core/src/primitive_docs.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-never_type `#![feature(never_type)]` S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-lang Relevant to the language team T-lang-docs Relevant to the lang-docs team. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants