-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Make typeck aware of uninhabited types #100288
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
Closed
+682
−274
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4095722
Remove unreachable_code check from liveness
camsteffen 1450957
Refactor Diverges in typeck
camsteffen 212a9ce
Check for uninhabited types in typeck
camsteffen 268654a
Add an allow unreachable_code
camsteffen f8dd09b
Fix tests
camsteffen e8de2e4
Add test for unused in builtin derives
camsteffen 11034e4
Bless tests
camsteffen 7533a94
rust-analyzer: Fix unreachable_code
camsteffen b71f85d
Bump ISSUES_ENTRY_LIMIT
camsteffen cdf138f
Freshen before uninhabited check
camsteffen 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
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
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
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
20 changes: 20 additions & 0 deletions
20
src/test/ui/consts/const-eval/write-to-uninhabited-enum-variant.stderr
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
warning: unreachable call | ||
--> $DIR/write-to-uninhabited-enum-variant.rs:22:9 | ||
| | ||
LL | Test1::B(x); | ||
| ^^^^^^^^ - this expression has type `Empty`, which is uninhabited | ||
| | | ||
| unreachable call | ||
| | ||
= note: `#[warn(unreachable_code)]` on by default | ||
|
||
warning: unreachable call | ||
--> $DIR/write-to-uninhabited-enum-variant.rs:26:9 | ||
| | ||
LL | Test2::B(x); | ||
| ^^^^^^^^ - this expression has type `Empty`, which is uninhabited | ||
| | | ||
| unreachable call | ||
|
||
warning: 2 warnings emitted | ||
|
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
warning: unreachable statement | ||
--> $DIR/issue-93161.rs:42:5 | ||
| | ||
LL | let bad = never(); | ||
| ------- this expression has type `Never`, which is uninhabited | ||
LL | result *= async { x + x }.await; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | ||
| | ||
= note: `#[warn(unreachable_code)]` on by default | ||
|
||
warning: unreachable call | ||
--> $DIR/issue-93161.rs:43:5 | ||
| | ||
LL | drop(bad); | ||
| ^^^^ --- this expression has type `Never`, which is uninhabited | ||
| | | ||
| unreachable call | ||
|
||
warning: 2 warnings emitted | ||
|
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
warning: unreachable call | ||
--> $DIR/issue-46519.rs:9:5 | ||
| | ||
LL | FontLanguageOverride::system_font(SystemFont::new()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----------------- this expression has type `SystemFont`, which is uninhabited | ||
| | | ||
| unreachable call | ||
| | ||
= note: `#[warn(unreachable_code)]` on by default | ||
|
||
warning: unreachable call | ||
--> $DIR/issue-46519.rs:22:9 | ||
| | ||
LL | FontLanguageOverride::System(f) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `SystemFont`, which is uninhabited | ||
| | | ||
| unreachable call | ||
|
||
warning: 2 warnings emitted | ||
|
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
warning: unreachable expression | ||
--> $DIR/issue-46855.rs:15:43 | ||
| | ||
LL | fn foo(xs: [(Never, u32); 1]) -> u32 { xs[0].1 } | ||
| -- ^ unreachable expression | ||
| | | ||
| this expression has type `[(Never, u32); 1]`, which is uninhabited | ||
| | ||
= note: `#[warn(unreachable_code)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![crate_type = "lib"] | ||
|
||
#![warn(unused)] | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub enum Void {} | ||
|
||
pub struct UnStruct { | ||
x: u32, | ||
v: Void | ||
} | ||
|
||
pub fn match_struct(x: UnStruct) { | ||
match x {} //~ non-exhaustive patterns: type `UnStruct` is non-empty | ||
} | ||
|
||
pub fn match_inhabited_field(x: UnStruct) { | ||
match x.x {} //~ non-exhaustive patterns: type `u32` is non-empty | ||
//~| unreachable expression | ||
} | ||
|
||
pub fn match_uninhabited_field(x: UnStruct) { | ||
match x.v {} // ok | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
warning: unreachable expression | ||
--> $DIR/uninhabited-struct-match.rs:18:11 | ||
| | ||
LL | match x.x {} | ||
| -^^ | ||
| | | ||
| unreachable expression | ||
| this expression has type `UnStruct`, which is uninhabited | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/uninhabited-struct-match.rs:3:9 | ||
| | ||
LL | #![warn(unused)] | ||
| ^^^^^^ | ||
= note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]` | ||
|
||
error[E0004]: non-exhaustive patterns: type `UnStruct` is non-empty | ||
--> $DIR/uninhabited-struct-match.rs:14:11 | ||
| | ||
LL | match x {} | ||
| ^ | ||
| | ||
note: `UnStruct` defined here | ||
--> $DIR/uninhabited-struct-match.rs:8:12 | ||
| | ||
LL | pub struct UnStruct { | ||
| ^^^^^^^^ | ||
= note: the matched value is of type `UnStruct` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown | ||
| | ||
LL ~ match x { | ||
LL + _ => todo!(), | ||
LL ~ } | ||
| | ||
|
||
error[E0004]: non-exhaustive patterns: type `u32` is non-empty | ||
--> $DIR/uninhabited-struct-match.rs:18:11 | ||
| | ||
LL | match x.x {} | ||
| ^^^ | ||
| | ||
= note: the matched value is of type `u32` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown | ||
| | ||
LL ~ match x.x { | ||
LL + _ => todo!(), | ||
LL ~ } | ||
| | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0004`. |
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
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.
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.
cc @rust-lang/types a small bugfix makes some code pass that didn't pass before, because it didn't realize that
get_void()
's result means the code is unreachable.