Skip to content

ICE: no type for local variable #117821

Closed

Description

auto-reduced (treereduce-rust):

fn main() {

    'while_loop: while true {
        break;
        break (None, |mask| {
            let bit = 1 << val;
        });
    }
}
original code

original:

#![feature(never_type)]

fn main() {
    let val: ! = loop { break break; };
    //~^ ERROR mismatched types

    loop {
        if true {
            break "asdf";
        } else {
            break 123; //~ ERROR mismatched types
        }
    };

    let _: i32 = loop {
        break "asdf"; //~ ERROR mismatched types
    };

    let _: i32 = 'outer_loop: loop {
        loop {
            break 'outer_loop "nope"; // entirely acceptable as an identifier. We currently do not attempt
            break "ok";
        };
    };

    'while_loop: while true { //~ WARN denote infinite loops with
        break;
        break (None, |mask| {
            let bit = 1 << val;
            if mask & bit == 0 {Some(mask|bit)} else {None}
        }); //~ ERROR `break` with value from a `while` loop
        loop {
            break 'while_loop 123;
            //~^ ERROR `break` with value from a `while` loop
            break 456;
            break 789;
        };
    }

    while let Some(_) = Some(()) {
        if break () { //~ ERROR `break` with value from a `while` loop
        }
    }

    while let Some(_) = Some(()) {
        break None;
        //~^ ERROR `break` with value from a `while` loop
    }

    'while_let_loop: while let Some(_) = Some(()) {
        loop {
            break 'while_let_loop "nope";
            //~^ ERROR `break` with value from a `while` loop
            break 33;
        };
    }

    for _ in &[1,2,3] {
        break (); //~ ERROR `break` with value from a `for` loop
        break [()];
        //~^ ERROR `break` with value from a `for` loop
    }

    'for_loop: for _ in &[1,2,3] {
        loop {
            break Some(3);
            break 'for_loop Some(17);
            //~^ ERROR `break` with value from a `for` loop
        };
    }

    let _: i32 = 'a: loop {
        let _: () = 'b: loop {
            break ('c: loop {
                break;
                break 'c 123; //~ ERROR mismatched types
            });
            break 'a 123;
        };
    };

    loop {
        break (break, break); //~ ERROR mismatched types
    };

    loop {
        break;
        break 2; //~ ERROR mismatched types
    };

    loop {
        break 2;
        break; //~ ERROR mismatched types
        break 4;
    };

    'LOOP: for _ in 0 .. 9 {
        break LOOP;
        //~^ ERROR cannot find value `LOOP` in this scope
    }

    let _ = 'a: loop {
        loop {
            break; // This doesn't affect the expected break type of the 'a loop
            loop {
                loop {
                    break 'a 1;
                }
            }
        }
        break; //~ ERROR mismatched types
    };

    let _ = 'a: loop {
        loop {
            break; // This doesn't affect the expected break type of the 'a loop
            loop {
                loop {
                    break 'l3 1;
                }
            }
        }
        break 'a; //~ ERROR mismatched types
    };

    loop {
        break;
        let _ = loop {
            break 2;
            loop {
                break;
            }
        };
        break 2; //~ ERROR mismatched types
    }

    'a: loop {
        break;
        let _ = 'a: loop {
            //~^ WARNING label name `'a` shadows a label name that is already in scope
            break 2;
            loop {
                break 'a; //~ ERROR mismatched types
            }
        };
        break 2; //~ ERROR mismatched types
    }

    'a: loop {
        break;
        let _ = 'a: loop {
            //~^ WARNING label name `'a` shadows a label name that is already in scope
            break 'a 2;
            loop {
                break 'a; //~ ERROR mismatched types
            }
        };
        break 2; //~ ERROR mismatched types
    };

    loop { // point at the return type
        break 2; //~ ERROR mismatched types
    }
}

Version information

rustc 1.75.0-nightly (1db4b1249 2023-11-11)
binary: rustc
commit-hash: 1db4b12494f698754b925f55061eb9e6b3241423
commit-date: 2023-11-11
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.4

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0425]: cannot find value `val` in this scope
 --> /tmp/icemaker_global_tempdir.ooBuJObI5lKd/rustc_testrunner_tmpdir_reporting.FJQt1QIxJXB0/mvce.rs:6:28
  |
6 |             let bit = 1 << val;
  |                            ^^^ not found in this scope

warning: unused label
 --> /tmp/icemaker_global_tempdir.ooBuJObI5lKd/rustc_testrunner_tmpdir_reporting.FJQt1QIxJXB0/mvce.rs:3:5
  |
3 |     'while_loop: while true {
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_labels)]` on by default

warning: denote infinite loops with `loop { ... }`
 --> /tmp/icemaker_global_tempdir.ooBuJObI5lKd/rustc_testrunner_tmpdir_reporting.FJQt1QIxJXB0/mvce.rs:3:5
  |
3 |     'while_loop: while true {
  |     ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
  |
  = note: `#[warn(while_true)]` on by default

error[E0571]: `break` with value from a `while` loop
 --> /tmp/icemaker_global_tempdir.ooBuJObI5lKd/rustc_testrunner_tmpdir_reporting.FJQt1QIxJXB0/mvce.rs:5:9
  |
3 |       'while_loop: while true {
  |       ----------------------- you can't `break` with a value in a `while` loop
4 |           break;
5 | /         break (None, |mask| {
6 | |             let bit = 1 << val;
7 | |         });
  | |__________^ can only break with a value inside `loop` or breakable block
  |
help: use `break` on its own without a value inside this `while` loop
  |
5 |         break;
  |         ~~~~~
help: alternatively, you might have meant to use the available loop label
  |
5 |         break 'while_loop;
  |               ~~~~~~~~~~~

warning: unreachable statement
 --> /tmp/icemaker_global_tempdir.ooBuJObI5lKd/rustc_testrunner_tmpdir_reporting.FJQt1QIxJXB0/mvce.rs:5:9
  |
4 |           break;
  |           ----- any code following this expression is unreachable
5 | /         break (None, |mask| {
6 | |             let bit = 1 << val;
7 | |         });
  | |___________^ unreachable statement
  |
  = note: `#[warn(unreachable_code)]` on by default

error: internal compiler error: compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs:134:13: no type for local variable HirId(DefId(0:3 ~ mvce[5667]::main).19) (local `let bit = 1 << val;`)
 --> /tmp/icemaker_global_tempdir.ooBuJObI5lKd/rustc_testrunner_tmpdir_reporting.FJQt1QIxJXB0/mvce.rs:6:13
  |
6 |             let bit = 1 << val;
  |             ^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/compiler/rustc_errors/src/lib.rs:1000:33:
Box<dyn Any>
stack backtrace:
   0:     0x7fcfd758b62c - std::backtrace_rs::backtrace::libunwind::trace::h60c98351b446b6fc
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fcfd758b62c - std::backtrace_rs::backtrace::trace_unsynchronized::h5f7f811450b9c6bf
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fcfd758b62c - std::sys_common::backtrace::_print_fmt::h0d5170c59727098e
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fcfd758b62c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h75fbf13e2e3eab42
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fcfd75de630 - core::fmt::rt::Argument::fmt::hf5a01755b8c97b0f
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/core/src/fmt/rt.rs:142:9
   5:     0x7fcfd75de630 - core::fmt::write::h21ffd88623dd8e8a
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fcfd757f4bf - std::io::Write::write_fmt::h192daa860eac75cb
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/io/mod.rs:1762:15
   7:     0x7fcfd758b414 - std::sys_common::backtrace::_print::h38432716ce8bcbbd
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fcfd758b414 - std::sys_common::backtrace::print::h1f49e3e8b68963a0
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fcfd758e0a7 - std::panicking::default_hook::{{closure}}::h1ab1b9b9fcc59e11
  10:     0x7fcfd758de0f - std::panicking::default_hook::h052ad26defc2b2d9
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/panicking.rs:292:9
  11:     0x7fcfda2ef410 - std[d0bee0584bbc47af]::panicking::update_hook::<alloc[dbc0aa70caf49578]::boxed::Box<rustc_driver_impl[cdb930f4dd583f9b]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fcfd758e7e8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h80a3a3c1c2830f76
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/alloc/src/boxed.rs:2021:9
  13:     0x7fcfd758e7e8 - std::panicking::rust_panic_with_hook::hd1cd0e2bf5e3508a
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/panicking.rs:783:13
  14:     0x7fcfda484394 - std[d0bee0584bbc47af]::panicking::begin_panic::<rustc_errors[666b6562ed3116f9]::ExplicitBug>::{closure#0}
  15:     0x7fcfda470756 - std[d0bee0584bbc47af]::sys_common::backtrace::__rust_end_short_backtrace::<std[d0bee0584bbc47af]::panicking::begin_panic<rustc_errors[666b6562ed3116f9]::ExplicitBug>::{closure#0}, !>
  16:     0x7fcfda465206 - std[d0bee0584bbc47af]::panicking::begin_panic::<rustc_errors[666b6562ed3116f9]::ExplicitBug>
  17:     0x7fcfda456d9e - <rustc_errors[666b6562ed3116f9]::HandlerInner>::span_bug::<rustc_span[c2bda87e20783fc8]::span_encoding::Span, alloc[dbc0aa70caf49578]::string::String>
  18:     0x7fcfda4569e8 - <rustc_errors[666b6562ed3116f9]::Handler>::span_bug::<rustc_span[c2bda87e20783fc8]::span_encoding::Span, alloc[dbc0aa70caf49578]::string::String>
  19:     0x7fcfda486feb - rustc_middle[8d21d7bf35089fff]::util::bug::opt_span_bug_fmt::<rustc_span[c2bda87e20783fc8]::span_encoding::Span>::{closure#0}
  20:     0x7fcfda4877ba - rustc_middle[8d21d7bf35089fff]::ty::context::tls::with_opt::<rustc_middle[8d21d7bf35089fff]::util::bug::opt_span_bug_fmt<rustc_span[c2bda87e20783fc8]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7fcfda478068 - rustc_middle[8d21d7bf35089fff]::ty::context::tls::with_context_opt::<rustc_middle[8d21d7bf35089fff]::ty::context::tls::with_opt<rustc_middle[8d21d7bf35089fff]::util::bug::opt_span_bug_fmt<rustc_span[c2bda87e20783fc8]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7fcfd9583224 - rustc_middle[8d21d7bf35089fff]::util::bug::span_bug_fmt::<rustc_span[c2bda87e20783fc8]::span_encoding::Span>
  23:     0x7fcfdbd0aa9b - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_local
  24:     0x7fcfd84adf80 - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_expr
  25:     0x7fcfd84aeb83 - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_expr
  26:     0x7fcfd84adc2d - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_expr
  27:     0x7fcfd84ae015 - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_expr
  28:     0x7fcfd84adf5a - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_expr
  29:     0x7fcfd84ae731 - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_expr
  30:     0x7fcfd84af0d1 - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_expr
  31:     0x7fcfd84af0d1 - <rustc_hir_typeck[48a7925dd0d8cef4]::writeback::WritebackCx as rustc_hir[b271daaa5d05d7e4]::intravisit::Visitor>::visit_expr
  32:     0x7fcfdbfc7dac - <rustc_hir_typeck[48a7925dd0d8cef4]::fn_ctxt::FnCtxt>::resolve_type_vars_in_body
  33:     0x7fcfdb91a721 - rustc_hir_typeck[48a7925dd0d8cef4]::typeck
  34:     0x7fcfdb918b93 - rustc_query_impl[26ab2eb5a4b73d01]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[26ab2eb5a4b73d01]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 8usize]>>
  35:     0x7fcfdb6eb4c3 - rustc_query_system[b68b7660e1b83fb7]::query::plumbing::try_execute_query::<rustc_query_impl[26ab2eb5a4b73d01]::DynamicConfig<rustc_query_system[b68b7660e1b83fb7]::query::caches::VecCache<rustc_span[c2bda87e20783fc8]::def_id::LocalDefId, rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[26ab2eb5a4b73d01]::plumbing::QueryCtxt, false>
  36:     0x7fcfdb6eb150 - rustc_query_impl[26ab2eb5a4b73d01]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7fcfdbbdf3c0 - rustc_hir_analysis[5a62dd6b63ca128a]::check_crate
  38:     0x7fcfdb958517 - rustc_interface[97b84efa53a847bb]::passes::analysis
  39:     0x7fcfdb958177 - rustc_query_impl[26ab2eb5a4b73d01]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[26ab2eb5a4b73d01]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 1usize]>>
  40:     0x7fcfdc5986e4 - rustc_query_system[b68b7660e1b83fb7]::query::plumbing::try_execute_query::<rustc_query_impl[26ab2eb5a4b73d01]::DynamicConfig<rustc_query_system[b68b7660e1b83fb7]::query::caches::SingleCache<rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[26ab2eb5a4b73d01]::plumbing::QueryCtxt, false>
  41:     0x7fcfdc5984d5 - rustc_query_impl[26ab2eb5a4b73d01]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7fcfdc5a10ff - rustc_interface[97b84efa53a847bb]::interface::run_compiler::<core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>, rustc_driver_impl[cdb930f4dd583f9b]::run_compiler::{closure#1}>::{closure#0}
  43:     0x7fcfdc5a841a - std[d0bee0584bbc47af]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[97b84efa53a847bb]::util::run_in_thread_with_globals<rustc_interface[97b84efa53a847bb]::util::run_in_thread_pool_with_globals<rustc_interface[97b84efa53a847bb]::interface::run_compiler<core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>, rustc_driver_impl[cdb930f4dd583f9b]::run_compiler::{closure#1}>::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>
  44:     0x7fcfdc5a8243 - <<std[d0bee0584bbc47af]::thread::Builder>::spawn_unchecked_<rustc_interface[97b84efa53a847bb]::util::run_in_thread_with_globals<rustc_interface[97b84efa53a847bb]::util::run_in_thread_pool_with_globals<rustc_interface[97b84efa53a847bb]::interface::run_compiler<core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>, rustc_driver_impl[cdb930f4dd583f9b]::run_compiler::{closure#1}>::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#1} as core[e724bad1857b6bd7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7fcfd75986a5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf4cdd73175754799
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/alloc/src/boxed.rs:2007:9
  46:     0x7fcfd75986a5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6955d1f30cee8d29
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/alloc/src/boxed.rs:2007:9
  47:     0x7fcfd75986a5 - std::sys::unix::thread::Thread::new::thread_start::h58dae6c91eb60bce
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys/unix/thread.rs:108:17
  48:     0x7fcfd73899eb - <unknown>
  49:     0x7fcfd740d7cc - <unknown>
  50:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.75.0-nightly (1db4b1249 2023-11-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors; 3 warnings emitted

Some errors have detailed explanations: E0425, E0571.
For more information about an error, try `rustc --explain E0425`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

C-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