Skip to content

Break with Value causes ICE #44416

Closed
Closed
@CasualX

Description

@CasualX

In reply to a comment on /r/rust I tried to write a macro to simulate for ... else and this causes an ICE

I tried this code: playground

macro_rules! for_else {
    ($i:ident in $iter:expr; $body:tt else $e:expr) => {
        'outer: loop {
            for $i in $iter $body
            break 'outer $e;
        }
    };
}

fn main() {
    let result = for_else!(i in 0..10; {
        break 'outer 2.71828;
    }
    else {
        3.141592
    });
    println!("Hello, {}!", result);
}

I expected to see this happen: This was a first attempt at a for_else macro, so I'm not sure what I expected! Certainly not an ICE however

Instead, this happened:

   Compiling playground v0.0.1 (file:///playground)
error[E0426]: use of undeclared label `'outer`
  --> src/main.rs:12:15
   |
12 |         break 'outer 2.71828;
   |               ^^^^^^ undeclared label `'outer`

error: internal compiler error: /checkout/src/librustc_typeck/check/mod.rs:1984: no type for node 16: expr 2.71828 (id=16) in fcx 0x7fe29eff3670

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.20.0 (f3d6973f4 2017-08-27) running on x86_64-unknown-linux-gnu

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

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Meta

Whatever's running today on the playground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions