Skip to content

ICE with const enum method returning Self #68684

Closed
@dylni

Description

@dylni

This code causes an ICE starting from Rust 1.41.0 (stable, beta, and nightly):

enum Enum {
    A(),
}

impl Enum {
    const fn a() -> Self {
        return Self::A();
    }
}

pub fn main() {
    const A: Enum = Enum::a();
}

Error:

error: internal compiler error: src/librustc_typeck/check/mod.rs:995: can't type-check body of DefId(0:5 ~ main[2fbc]::Enum[0]::A[0]::{{constructor}}[0])
 --> main.rs:2:5
  |
2 |     A(),
  |     ^^^

No extra flags were added. It also happens in release mode.

rustc main.rs

Rust Playground is at version 1.40.0 and doesn't have the error on stable:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6683265b3123c0a6835431de2f0c6897

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions