Skip to content

ICE when using typeof #42060

Closed
Closed
@jFransham

Description

@jFransham

Obviously typeof isn't used in the current version of Rust, but if you do try to use it you get some strange behaviour. rustc correctly reports that typeof is unimplemented, and the error message is sensible if used with a constant expression, but using it with local variables causes an ICE.

Minimum code sample:

fn main() {
    let thing = ();
    let other: typeof(thing) = thing;
}

I'd expect this to return the same error as doing typeof(5), which is:

rustc 1.17.0 (56124baa9 2017-04-24)
error[E0516]: `typeof` is a reserved keyword but unimplemented
 --> <anon>:3:16
  |
3 |     let other: typeof(5) = thing;
  |                ^^^^^^^^^ reserved keyword

error: aborting due to previous error

But instead I get this:

rustc 1.17.0 (56124baa9 2017-04-24)
error[E0516]: `typeof` is a reserved keyword but unimplemented
 --> <anon>:3:16
  |
3 |     let other: typeof(thing) = thing;
  |                ^^^^^^^^^^^^^ reserved keyword

error: internal compiler error: /checkout/src/librustc_typeck/check/mod.rs:1527: no type for local variable local thing (id=8)
 --> <anon>:3:23
  |
3 |     let other: typeof(thing) = thing;
  |                       ^^^^^

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-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