Skip to content

ICE involving catch_expr and never_type #43335

Closed

Description

@crumblingstatue
#![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 | | }
   | |_^

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on Jul 19, 2017
  2. crumblingstatue commented on Jul 19, 2017

    @crumblingstatue
    ContributorAuthor

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

  3. scottmcm commented on Sep 2, 2017

    @scottmcm
    Member

    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: () })
    
  4. varkor commented on Feb 11, 2018

    @varkor
    Contributor

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

  5. added
    F-try_blocks`#![feature(try_blocks)]`
    and removed on Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-try_blocks`#![feature(try_blocks)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions