Skip to content

ICE involving catch_expr and never_type #43335

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

Closed
crumblingstatue opened this issue Jul 19, 2017 · 3 comments
Closed

ICE involving catch_expr and never_type #43335

crumblingstatue opened this issue Jul 19, 2017 · 3 comments
Labels
C-bug Category: This is a bug. F-try_blocks `#![feature(try_blocks)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@crumblingstatue
Copy link
Contributor

#![feature(catch_expr, never_type)]

struct Error {
    cause: &'static str,
}

fn oops() -> Result<(), Error> {
    Err(Error { cause: "epic fail" } )
}

fn main() {
    let Err(Error { cause }): Result<!, Error> = do catch {
        oops()?;
        return; // OK
    };
    eprintln!("Nuclear meltdown initiated: {}", cause);
}
error: internal compiler error: broken MIR (_1 = ()): bad assignment (! = ()): Sorts(ExpectedFound { expected: !, found: () })
  --> src/main.rs:11:11
   |
11 |   fn main() {
   |  ___________^
12 | |     let Err(Error { cause }): Result<!, Error> = do catch {
13 | |         oops()?;
14 | |         return; // OK
15 | |     };
16 | |     eprintln!("Nuclear meltdown initiated: {}", cause);
17 | | }
   | |_^

@Mark-Simulacrum Mark-Simulacrum added A-catch I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jul 19, 2017
@crumblingstatue
Copy link
Contributor Author

Interestingly, if you add return (); at the end, the ICE disappears, leading to #43336.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@scottmcm
Copy link
Member

scottmcm commented Sep 2, 2017

Looks like this can be triggered with only catch_expr (without never_type) by using a loop:

fn anaconda<I: Iterator>(mut it: I) {
    let _: Result<(),()> = do catch {
        loop {
            it.next().ok_or(())?;
        }
    };
}

https://play.rust-lang.org/?gist=32c33a234dd7a8d6a8e961d4121b885e&version=nightly

error: internal compiler error: broken MIR in NodeId(4) (_3 = ()): bad assignment (! = ()): Sorts(ExpectedFound { expected: !, found: () })

@varkor
Copy link
Member

varkor commented Feb 11, 2018

Looks like this is fixed now (I suspect by #47746).

@fmease fmease added F-try_blocks `#![feature(try_blocks)]` and removed A-catch labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-try_blocks `#![feature(try_blocks)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants