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

ICE with const enum method returning Self #68684

Closed
dylni opened this issue Jan 31, 2020 · 5 comments · Fixed by #69166
Closed

ICE with const enum method returning Self #68684

dylni opened this issue Jan 31, 2020 · 5 comments · Fixed by #69166
Assignees
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dylni
Copy link
Contributor

dylni commented Jan 31, 2020

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

@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 regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-eval Area: Constant evaluation (MIR interpretation) labels Jan 31, 2020
@Centril
Copy link
Contributor

Centril commented Jan 31, 2020

Another version:

enum _Enum {
    A(),
}

type _E = _Enum;

const fn _a() -> _Enum {
    _E::A() // Changing to `_Enum::A()` makes it compile.
}

const _A: _Enum = _a();

fn main() {}

@Centril
Copy link
Contributor

Centril commented Jan 31, 2020

cc @oli-obk @matthewjasper

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 1, 2020
@JohnTitor
Copy link
Member

Bisected: 2539b5f, #66294

@matthewjasper
Copy link
Contributor

This should be checking tcx.has_typeck_tables(def_id) before calling typeck_tables_of:

if def_id.is_local() && tcx.typeck_tables_of(def_id).tainted_by_errors {

@pnkfelix
Copy link
Member

pnkfelix commented Feb 6, 2020

triage: P-high. Removing nomination. Assigning to self.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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.

7 participants