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

Internal compiler error with enums #62375

Closed
crone123 opened this issue Jul 4, 2019 · 6 comments · Fixed by #62377
Closed

Internal compiler error with enums #62375

crone123 opened this issue Jul 4, 2019 · 6 comments · Fixed by #62377
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@crone123
Copy link

crone123 commented Jul 4, 2019

Hello,
I found a bug while developing a project who produce an internal error.

I create this code to reproduce the error:

struct TypeA
{
    attr: String,
    attr2: usize,
}
struct TypeB
{
    attr: usize,
    attr2: Vec<String>,
}
enum En
{
    Value(TypeA), OtherValue(TypeB), None
}
fn main()
{
    let a = En::Value(TypeA{attr: "Hello".to_owned(), attr2: 12});
    if a == En::Value
    {
        println!("Value !");
    }
}

I got this error:
image

If you do the same using an Option, for example:

let a = Some(12);
if a == Some // Produce an error, but not a compiler crash
{
///
}

But if you do this:

struct TypeA
{
    attr: String,
    attr2: usize,
}
fn main()
{
    let a = Some(TypeA{attr: "Hello".to_owned(), attr2: 12});
    if a == Some
    {
        println!("Value !");
    }
}

You got another internal compiler error:
image

And to know: There is a correct way to do this without a match?
I try this, but it wasn't accepted:

if myVar == MyEnum::MyValue(_)  {...}

Thank you

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 4, 2019
@hellow554
Copy link
Contributor

hellow554 commented Jul 4, 2019

Does not panic on nightly-2019-06-17 (playground nightly). Must have been fixed. @jonas-schievink E-needstest?

@hellow554
Copy link
Contributor

@crone123 you should update your rust rustup update :)

@crone123
Copy link
Author

crone123 commented Jul 4, 2019

Hello,
Ok with an update it's fixed:
image

Thank you :)

But, there is a way to have auto updates on Linux?
There is a way to check the enum value type without checking the content wrapped? (with a if, not a match)

@jonas-schievink jonas-schievink added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed I-nominated labels Jul 4, 2019
wesleywiser added a commit to wesleywiser/rust that referenced this issue Jul 4, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jul 4, 2019

There is a way to check the enum value type without checking the content wrapped? (with a if, not a match)

@crone123: You can use the Option::is_some method like so: if a.is_some() { ... }

(Or you can say if let Some(_) = a { ... }, which I think is better style, but there are scenarios where one must resort to the is_some method.)

@hellow554
Copy link
Contributor

For the record: has been fixed in 6c22051 #60073

@crone123
Copy link
Author

crone123 commented Jul 5, 2019

There is a way to check the enum value type without checking the content wrapped? (with a if, not a match)

@crone123: You can use the Option::is_some method like so: if a.is_some() { ... }

(Or you can say if let Some(_) = a { ... }, which I think is better style, but there are scenarios where one must resort to the is_some method.)

Ok thank you !
I forgot the "let" before the Some(_), I think it's the reason why it's doesn't works.

Centril added a commit to Centril/rust that referenced this issue Jul 5, 2019
bors added a commit that referenced this issue Jul 5, 2019
Rollup of 8 pull requests

Successful merges:

 - #60260 (Add support for UWP targets)
 - #62151 (Update linked OpenSSL version)
 - #62245 (Miri engine: support extra function (pointer) values)
 - #62257 (forward read_c_str method from Memory to Alloc)
 - #62264 (Fix perf regression from Miri Machine trait changes)
 - #62296 (request at least ptr-size alignment from posix_memalign)
 - #62329 (Remove support for 1-token lookahead from the lexer)
 - #62377 (Add test for ICE #62375)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this issue Jul 6, 2019
bors added a commit that referenced this issue Jul 6, 2019
Rollup of 7 pull requests

Successful merges:

 - #62151 (Update linked OpenSSL version)
 - #62245 (Miri engine: support extra function (pointer) values)
 - #62257 (forward read_c_str method from Memory to Alloc)
 - #62264 (Fix perf regression from Miri Machine trait changes)
 - #62296 (request at least ptr-size alignment from posix_memalign)
 - #62329 (Remove support for 1-token lookahead from the lexer)
 - #62377 (Add test for ICE #62375)

Failed merges:

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants