Skip to content

Internal compiler error with enums #62375

@crone123

Description

@crone123

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions