Skip to content
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 test self-in-enum-definition #62916

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[repr(u8)]
enum Alpha {
V1 = 41,
V2 = Self::V1 as u8 + 1, // OK -- but why?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really... why?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it felt familiar... 😭.

At some point we should do what @RalfJung suggested in #61723 (comment) since Ralf is right that this is so incredibly niche and imo clearly a bug...

Oh well... not much to do about it here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted the comment to refer to #50072... Should be good to merge now. :)

V3 = Self::V1 {} as u8 + 2, //~ ERROR cycle detected when const-evaluating
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error[E0391]: cycle detected when const-evaluating + checking `Alpha::V3::{{constant}}#0`
--> $DIR/self-in-enum-definition.rs:5:10
|
LL | V3 = Self::V1 {} as u8 + 2,
| ^^^^^^^^
|
note: ...which requires const-evaluating `Alpha::V3::{{constant}}#0`...
--> $DIR/self-in-enum-definition.rs:5:10
|
LL | V3 = Self::V1 {} as u8 + 2,
| ^^^^^^^^
= note: ...which requires computing layout of `Alpha`...
= note: ...which again requires const-evaluating + checking `Alpha::V3::{{constant}}#0`, completing the cycle
note: cycle used when collecting item types in top-level module
--> $DIR/self-in-enum-definition.rs:1:1
|
LL | / #[repr(u8)]
LL | | enum Alpha {
LL | | V1 = 41,
LL | | V2 = Self::V1 as u8 + 1, // OK -- but why?
... |
LL | |
LL | | fn main() {}
| |____________^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0391`.