-
Notifications
You must be signed in to change notification settings - Fork 593
Update for stabilization of the never type #2283
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
Open
ehuss
wants to merge
7
commits into
rust-lang:master
Choose a base branch
from
ehuss:stabilize-never
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+39
−39
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7eb935b
Remove type.never.constraint
ehuss bdc68a0
Move type.never.intro to the top
ehuss d81f5ab
Move never type example, and update for stabilization
ehuss 1efe67f
Update never type fallback for stabilization
ehuss 1733d95
Update examples for never type stabilization
ehuss 6e3f79b
Remove "other" on never type coercion
ehuss 6e3c505
Link to divergence in never type intro
ehuss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,42 @@ | ||
| r[type.never] | ||
| # Never type | ||
|
|
||
| r[type.never.syntax] | ||
| ```grammar,types | ||
| NeverType -> `!` | ||
| ``` | ||
|
|
||
| r[type.never.intro] | ||
| The never type `!` is a type with no values, representing the result of computations that never complete. | ||
| The never type `!` is a type with no values, representing computations that never complete, also known as [diverging][divergence] computations. | ||
|
|
||
| r[type.never.coercion] | ||
| Expressions of type `!` can be coerced into any other type. | ||
| > [!EXAMPLE] | ||
| > ```rust | ||
| > fn foo() -> ! { | ||
| > panic!("This call never returns."); | ||
| > } | ||
| > ``` | ||
| > | ||
| > ```rust | ||
| > unsafe extern "C" { | ||
| > pub safe fn no_return_extern_func() -> !; | ||
| > } | ||
| > ``` | ||
| > | ||
| > ```rust | ||
| > # use std::str::FromStr; | ||
| > struct Anything(String); | ||
| > | ||
| > impl FromStr for Anything { | ||
| > type Err = !; | ||
| > | ||
| > fn from_str(s: &str) -> Result<Self, !> { | ||
| > Ok(Anything(s.to_owned())) | ||
| > } | ||
| > } | ||
| > | ||
| > let Ok(s) = Anything::from_str("example"); | ||
| > ``` | ||
|
|
||
| r[type.never.constraint] | ||
| The `!` type can **only** appear in function return types presently, indicating it is a diverging function that never returns. | ||
|
|
||
| ```rust | ||
| fn foo() -> ! { | ||
| panic!("This call never returns."); | ||
| } | ||
| r[type.never.syntax] | ||
| ```grammar,types | ||
| NeverType -> `!` | ||
| ``` | ||
|
|
||
| ```rust | ||
| unsafe extern "C" { | ||
| pub safe fn no_return_extern_func() -> !; | ||
| } | ||
| ``` | ||
| r[type.never.coercion] | ||
| Expressions of type `!` can be coerced into any type. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
A shame that we can't represent "before rust x.y.z with edition < 2024"...
View changes since the review