Skip to content

Internal compiler error when attempting to implement an associated const with a local variable #44239

Closed
@petertodd

Description

@petertodd

Specifically this code:

trait Foo {
    const N: usize;
}

fn main() {
    struct MyFoo;

    let n = 0;

    impl Foo for MyFoo {
        const N: usize = n;
    }   
}

results in the following error message:

$ rustc test.rs 
error: internal compiler error: /checkout/src/librustc_typeck/check/mod.rs:1846: no type for local variable local n (id=15)
  --> test.rs:11:26
   |
11 |         const N: usize = n;
   |                            ^

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.21.0-nightly (97b01abf3 2017-08-31) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:439:8
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Expected behavior: While I can understand if this level of meta isn't possible, it should give a proper error message! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.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