-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
typeck: always expose explicit enum discriminant AnonConst
s' parent in generics_of
.
#70825
Merged
bors
merged 3 commits into
rust-lang:master
from
eddyb:enum-discr-correct-generics-parent
May 3, 2020
+126
−19
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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
16 changes: 16 additions & 0 deletions
16
src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs
This file contains 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,16 @@ | ||
#![feature(arbitrary_enum_discriminant, core_intrinsics)] | ||
|
||
extern crate core; | ||
use core::intrinsics::discriminant_value; | ||
|
||
#[repr(usize)] | ||
enum MyWeirdOption<T> { | ||
None = 0, | ||
Some(T) = std::mem::size_of::<T>(), | ||
//~^ ERROR constant expression depends on a generic parameter | ||
} | ||
|
||
fn main() { | ||
assert_eq!(discriminant_value(&MyWeirdOption::<u8>::None), 0); | ||
assert_eq!(discriminant_value(&MyWeirdOption::Some(0u8)), 1); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr
This file contains 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,10 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/issue-70453-generics-in-discr-ice-2.rs:9:15 | ||
| | ||
LL | Some(T) = std::mem::size_of::<T>(), | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
17 changes: 17 additions & 0 deletions
17
src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.rs
This file contains 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,17 @@ | ||
#![feature(core_intrinsics)] | ||
|
||
extern crate core; | ||
use core::intrinsics::discriminant_value; | ||
|
||
#[repr(usize)] | ||
enum MyWeirdOption<T> { | ||
//~^ ERROR parameter `T` is never used | ||
None = 0, | ||
Some = std::mem::size_of::<T>(), | ||
//~^ ERROR constant expression depends on a generic parameter | ||
} | ||
|
||
fn main() { | ||
assert_eq!(discriminant_value(&MyWeirdOption::<u8>::None), 0); | ||
assert_eq!(discriminant_value(&MyWeirdOption::<u8>::Some), 1); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr
This file contains 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,19 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/issue-70453-generics-in-discr-ice.rs:10:12 | ||
| | ||
LL | Some = std::mem::size_of::<T>(), | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error[E0392]: parameter `T` is never used | ||
--> $DIR/issue-70453-generics-in-discr-ice.rs:7:20 | ||
| | ||
LL | enum MyWeirdOption<T> { | ||
| ^ unused parameter | ||
| | ||
= help: consider removing `T`, referring to it in a field, or using a marker such as `std::marker::PhantomData` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0392`. |
17 changes: 17 additions & 0 deletions
17
src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs
This file contains 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,17 @@ | ||
// run-pass | ||
|
||
#![feature(arbitrary_enum_discriminant, core_intrinsics)] | ||
|
||
extern crate core; | ||
use core::intrinsics::discriminant_value; | ||
|
||
#[repr(usize)] | ||
enum MyWeirdOption<T> { | ||
None = 0, | ||
Some(T) = core::mem::size_of::<*mut T>(), | ||
} | ||
|
||
fn main() { | ||
assert_eq!(discriminant_value(&MyWeirdOption::<()>::None), 0); | ||
assert_eq!(discriminant_value(&MyWeirdOption::Some(())), core::mem::size_of::<usize>() as u64); | ||
} |
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.
Comment could use some elaboration regarding the "why" as well as a link towards #70453.
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.
Just to make sure I'm following along, this concept of "must be evaluatable" is going to ultimately be true for any const expression, right? I think this is the basic WF criteria we are working towards?
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.
Yes, at the minimum any
ty::Const
used in the typesystem (array lengths and args to const params). Whileenum
discrminants aren't that, they do require strict checks (no overlap), for which successful evaluatability is a bare minimum.