Closed

Description
I tried to compile some massive project and the rust compiler unexpectedly panicked. Luckily, I have managed to replicate the error in a small, reproducible example (still panics on rust playground online, 11 lines of code):
fn main() {
let c = |p| {
'main: for h in p..(p + 10) {
let j = |k| {
break 'main;
};
j(p);
}
};
c(1);
}
I expected a regular error without a panic, but the compiler simply halted.
Output of RUST_BACKTRACE=1 rustc ~/Desktop/rust_bug.rs -o bug.out -C debuginfo=2:
error[E0267]: `break` inside of a closure
--> /home/liam/Desktop/rust_bug.rs:5:17
|
5 | break 'main;
| ^^^^^^^^^^^ cannot break inside of a closure
error: internal compiler error: src/librustc_typeck/check/mod.rs:509: could not find enclosing breakable with id HirId { owner: DefIndex(12), local_id: 34 }
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:644:9
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:47
3: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:36
4: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:200
5: std::panicking::default_hook
at src/libstd/panicking.rs:214
6: rustc::util::common::panic_hook
7: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:481
8: std::panicking::begin_panic
9: rustc_errors::Handler::bug
10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
11: rustc::ty::context::tls::with_opt::{{closure}}
12: rustc::ty::context::tls::with_context_opt
13: rustc::ty::context::tls::with_opt
14: rustc::util::bug::opt_span_bug_fmt
15: rustc::util::bug::bug_fmt
16: rustc_typeck::check::EnclosingBreakables::find_breakable::{{closure}}
17: rustc_typeck::check::EnclosingBreakables::find_breakable
18: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
19: rustc_typeck::check::FnCtxt::check_stmt
20: rustc_typeck::check::FnCtxt::check_block_with_expected
21: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
22: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
23: rustc_typeck::check::check_fn
24: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::check_expr_closure
25: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
26: rustc_typeck::check::FnCtxt::check_decl_initializer
27: rustc_typeck::check::FnCtxt::check_decl_local
28: rustc_typeck::check::FnCtxt::check_stmt
29: rustc_typeck::check::FnCtxt::check_block_with_expected
30: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
31: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_meets_expectation_or_error
32: rustc_typeck::check::FnCtxt::check_stmt
33: rustc_typeck::check::FnCtxt::check_block_with_expected
34: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
35: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match
36: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
37: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
38: rustc_typeck::check::FnCtxt::check_block_with_expected
39: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
40: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
41: rustc_typeck::check::check_fn
42: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::check_expr_closure
43: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
44: rustc_typeck::check::FnCtxt::check_decl_initializer
45: rustc_typeck::check::FnCtxt::check_decl_local
46: rustc_typeck::check::FnCtxt::check_stmt
47: rustc_typeck::check::FnCtxt::check_block_with_expected
48: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
49: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
50: rustc_typeck::check::check_fn
51: rustc::ty::context::GlobalCtxt::enter_local
52: rustc_typeck::check::typeck_tables_of
53: rustc::ty::query::__query_compute::typeck_tables_of
54: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
55: rustc::dep_graph::graph::DepGraph::with_task_impl
56: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
57: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
58: rustc_typeck::check::typeck_item_bodies
59: rustc::ty::query::__query_compute::typeck_item_bodies
60: rustc::dep_graph::graph::DepGraph::with_task_impl
61: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
62: rustc::util::common::time
63: rustc_typeck::check_crate
64: rustc_interface::passes::analysis
65: rustc::ty::query::__query_compute::analysis
66: rustc::dep_graph::graph::DepGraph::with_task_impl
67: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
68: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
69: rustc_interface::passes::create_global_ctxt::{{closure}}
70: rustc_interface::interface::run_compiler_in_existing_thread_pool
71: std::thread::local::LocalKey<T>::with
72: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [typeck_tables_of] processing `main`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0267`.
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.38.0-nightly (04b88a9eb 2019-07-29) running on x86_64-unknown-linux-gnu
note: compiler flags: -C debuginfo=2
Output of rustc --version --verbose
:
rustc 1.38.0-nightly (04b88a9eb 2019-07-29)
binary: rustc
commit-hash: 04b88a9eba8abbac87eddcb2998beea09589c2c9
commit-date: 2019-07-29
host: x86_64-unknown-linux-gnu
release: 1.38.0-nightly
LLVM version: 9.0