ice: unexpected body ty: {type error} · Issue #120779 · rust-lang/rust (original) (raw)

auto-reduced (treereduce-rust):

fn range_shadow_lit() { let x = 0;

assert_eq!(2, match val() {
    1..=2 if false =|value_ref, item| 1,
    1 => 2,
    _ => 3
});

// ditto

}

original code

original:

// run-pass

// Tests that match expression handles overlapped literal and range // properly in the presence of guard function.

fn val() -> usize { 1 }

static CONST: usize = 1;

pub fn main() { lit_shadow_range(); range_shadow_lit(); range_shadow_range(); multi_pats_shadow_lit(); multi_pats_shadow_range(); lit_shadow_multi_pats(); range_shadow_multi_pats(); misc(); }

fn lit_shadow_range() { assert_eq!(2, match 1 { 1 if false => 1, 1..=2 => 2, _ => 3 });

let x = 0;
assert_eq!(2, match x+1 {
    0 => 0,
    1 if false => 1,
    1..=2 => 2,
    _ => 3
});

assert_eq!(2, match val() {
    1 if false => 1,
    1..=2 => 2,
    _ => 3
});

assert_eq!(2, match CONST {
    0 => 0,
    1 if false => 1,
    1..=2 => 2,
    _ => 3
});

// value is out of the range of second arm, should match wildcard pattern
assert_eq!(3, match 3 {
    1 if false => 1,
    1..=2 => 2,
    _ => 3
});

}

fn range_shadow_lit() { assert_eq!(2, match 1 { 1..=2 if false => 1, 1 => 2, _ => 3 });

let x = 0;
assert_eq!(2, match x+1 {
    0 => 0,
    1..=2 if false => 1,
    1 => 2,
    _ => 3
});

assert_eq!(2, match val() {
    1..=2 if false =|value_ref, item| 1,
    1 => 2,
    _ => 3
});

assert_eq!(2, match CONST {
    0 => 0,
    1..=2 if false => 1,
    1 => 2,
    _ => 3
});

// ditto
assert_eq!(3, match 3 {
    1..=2 if false => 1,
    1 => 2,
    _ => 3
});

}

fn range_shadow_range() { assert_eq!(2, match 1 { 0..=2 if false => 1, 1..=3 => 2, _ => 3, });

let x = 0;
assert_eq!(2, match x+1 {
    100 => 0,
    0..=2 if false => 1,
    1..=3 => 2,
    _ => 3,
});

assert_eq!(2, match val() {
    0..=2 if false => 1,
    1..=3 => 2,
    _ => 3,
});

assert_eq!(2, match CONST {
    100 => 0,
    0..=2 if false => 1,
    1..=3 => 2,
    _ => 3,
});

// ditto
assert_eq!(3, match 5 {
    0..=2 if false => 1,
    1..=3 => 2,
    _ => 3,
});

}

fn multi_pats_shadow_lit() { assert_eq!(2, match 1 { 100 => 0, 0 | 1..=10 if false => 1, 1 => 2, _ => 3, }); }

fn multi_pats_shadow_range() { assert_eq!(2, match 1 { 100 => 0, 0 | 1..=10 if false => 1, 1..=3 => 2, _ => 3, }); }

fn lit_shadow_multi_pats() { assert_eq!(2, match 1 { 100 => 0, 1 if false => 1, 0 | 1..=10 => 2, _ => 3, }); }

fn range_shadow_multi_pats() { assert_eq!(2, match 1 { 100 => 0, 1..=3 if false => 1, 0 | 1..=10 => 2, _ => 3, }); }

fn misc() { enum Foo { Bar(#[allow(dead_code)] usize, bool) } // This test basically mimics how trace_macros! macro is implemented, // which is a rare combination of vector patterns, multiple wild-card // patterns and guard functions. let r = match [Foo::Bar(0, false)] { [Foo::Bar(, pred)] if pred => 1, [Foo::Bar(, pred)] if !pred => 2, _ => 0, }; assert_eq!(2, r); }

Version information

rustc 1.78.0-nightly (af88f7db5 2024-02-08)
binary: rustc
commit-hash: af88f7db51f6f2a1472f9279d7c7e7c822afff77
commit-date: 2024-02-08
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

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

Program output

error: `match` arm with no body
 --> /tmp/icemaker_global_tempdir.BIS0hp39G4ft/rustc_testrunner_tmpdir_reporting.WlOHJlWBRsBO/mvce.rs:5:9
  |
5 |         1..=2 if false =|value_ref, item| 1,
  |         ^^^^^- help: add a body after the pattern: `=> todo!(),`

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.BIS0hp39G4ft/rustc_testrunner_tmpdir_reporting.WlOHJlWBRsBO/mvce.rs:11:2
   |
11 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.BIS0hp39G4ft/rustc_testrunner_tmpdir_reporting.WlOHJlWBRsBO/mvce.rs`

error[E0425]: cannot find function `val` in this scope
 --> /tmp/icemaker_global_tempdir.BIS0hp39G4ft/rustc_testrunner_tmpdir_reporting.WlOHJlWBRsBO/mvce.rs:4:25
  |
4 |     assert_eq!(2, match val() {
  |                         ^^^ not found in this scope

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.BIS0hp39G4ft/rustc_testrunner_tmpdir_reporting.WlOHJlWBRsBO/mvce.rs:5:18
  |
5 |         1..=2 if false =|value_ref, item| 1,
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`

error: internal compiler error: compiler/rustc_mir_transform/src/abort_unwinding_calls.rs:44:18: unexpected body ty: {type error}
 --> /tmp/icemaker_global_tempdir.BIS0hp39G4ft/rustc_testrunner_tmpdir_reporting.WlOHJlWBRsBO/mvce.rs:5:25
  |
5 |         1..=2 if false =|value_ref, item| 1,
  |                         ^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/compiler/rustc_errors/src/lib.rs:849:41:
Box<dyn Any>
stack backtrace:
   0:     0x7fdfb358bdd6 - std::backtrace_rs::backtrace::libunwind::trace::hf92ca961e56825b0
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fdfb358bdd6 - std::backtrace_rs::backtrace::trace_unsynchronized::h23f341cc1a6c507f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fdfb358bdd6 - std::sys_common::backtrace::_print_fmt::ha5a5ba44893edc7f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fdfb358bdd6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h667e6ba5a1d3724e
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fdfb35de830 - core::fmt::rt::Argument::fmt::h06c91f49bef095fb
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/core/src/fmt/rt.rs:142:9
   5:     0x7fdfb35de830 - core::fmt::write::h8e4b31b0aa81d13f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fdfb357f64f - std::io::Write::write_fmt::h4c479f5c53dfe78c
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/io/mod.rs:1854:15
   7:     0x7fdfb358bbb4 - std::sys_common::backtrace::_print::he414f5864df55ed1
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fdfb358bbb4 - std::sys_common::backtrace::print::h939e58bdcc61d57d
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fdfb358e947 - std::panicking::default_hook::{{closure}}::h244e48e05cd664b2
  10:     0x7fdfb358e6a9 - std::panicking::default_hook::hf842080c39497dac
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/panicking.rs:292:9
  11:     0x7fdfb63454ac - std[f801e042bca9681]::panicking::update_hook::<alloc[1377227f5558ef79]::boxed::Box<rustc_driver_impl[65af58b05c4f91ef]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fdfb358f096 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>:🤙:hee9c09a26ce84f59
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2029:9
  13:     0x7fdfb358f096 - std::panicking::rust_panic_with_hook::h83c20f9191a2a712
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/panicking.rs:785:13
  14:     0x7fdfb6376f04 - std[f801e042bca9681]::panicking::begin_panic::<rustc_errors[89ec94d63507ad05]::ExplicitBug>::{closure#0}
  15:     0x7fdfb63735f6 - std[f801e042bca9681]::sys_common::backtrace::__rust_end_short_backtrace::<std[f801e042bca9681]::panicking::begin_panic<rustc_errors[89ec94d63507ad05]::ExplicitBug>::{closure#0}, !>
  16:     0x7fdfb636ea66 - std[f801e042bca9681]::panicking::begin_panic::<rustc_errors[89ec94d63507ad05]::ExplicitBug>
  17:     0x7fdfb6382b61 - <rustc_errors[89ec94d63507ad05]::diagnostic_builder::BugAbort as rustc_errors[89ec94d63507ad05]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7fdfb68ef8dd - rustc_middle[2cc1c6e52ad3d43f]::util:🐛:opt_span_bug_fmt::<rustc_span[467c297c964200f6]::span_encoding::Span>::{closure#0}
  19:     0x7fdfb68ef90a - rustc_middle[2cc1c6e52ad3d43f]::ty::context::tls::with_opt::<rustc_middle[2cc1c6e52ad3d43f]::util:🐛:opt_span_bug_fmt<rustc_span[467c297c964200f6]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7fdfb68e5da8 - rustc_middle[2cc1c6e52ad3d43f]::ty::context::tls::with_context_opt::<rustc_middle[2cc1c6e52ad3d43f]::ty::context::tls::with_opt<rustc_middle[2cc1c6e52ad3d43f]::util:🐛:opt_span_bug_fmt<rustc_span[467c297c964200f6]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7fdfb68de164 - rustc_middle[2cc1c6e52ad3d43f]::util:🐛:span_bug_fmt::<rustc_span[467c297c964200f6]::span_encoding::Span>
  22:     0x7fdfb771f700 - <rustc_mir_transform[f04df7d082cb6ded]::abort_unwinding_calls::AbortUnwindingCalls as rustc_middle[2cc1c6e52ad3d43f]::mir::MirPass>::run_pass
  23:     0x7fdfb76123e6 - rustc_mir_transform[f04df7d082cb6ded]::pass_manager::run_passes_inner
  24:     0x7fdfb4a91352 - rustc_mir_transform[f04df7d082cb6ded]::mir_drops_elaborated_and_const_checked
  25:     0x7fdfb77e3675 - rustc_query_impl[5ca841c3c79670ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ca841c3c79670ea]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7fdfb77e38fa - rustc_query_system[125a8aa150dcabe3]::query::plumbing::try_execute_query::<rustc_query_impl[5ca841c3c79670ea]::DynamicConfig<rustc_query_system[125a8aa150dcabe3]::query::caches::VecCache<rustc_span[467c297c964200f6]::def_id::LocalDefId, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5ca841c3c79670ea]::plumbing::QueryCtxt, false>
  27:     0x7fdfb77e31d4 - rustc_query_impl[5ca841c3c79670ea]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7fdfb7fd44ed - rustc_interface[c2746bee48761670]::passes::analysis
  29:     0x7fdfb7fd3bdf - rustc_query_impl[5ca841c3c79670ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ca841c3c79670ea]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 1usize]>>
  30:     0x7fdfb82a17b2 - rustc_query_system[125a8aa150dcabe3]::query::plumbing::try_execute_query::<rustc_query_impl[5ca841c3c79670ea]::DynamicConfig<rustc_query_system[125a8aa150dcabe3]::query::caches::SingleCache<rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5ca841c3c79670ea]::plumbing::QueryCtxt, false>
  31:     0x7fdfb82a1515 - rustc_query_impl[5ca841c3c79670ea]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7fdfb82e2436 - rustc_interface[c2746bee48761670]::interface::run_compiler::<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}
  33:     0x7fdfb7f60248 - std[f801e042bca9681]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c2746bee48761670]::util::run_in_thread_with_globals<rustc_interface[c2746bee48761670]::util::run_in_thread_pool_with_globals<rustc_interface[c2746bee48761670]::interface::run_compiler<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>
  34:     0x7fdfb7f60077 - <<std[f801e042bca9681]::thread::Builder>::spawn_unchecked_<rustc_interface[c2746bee48761670]::util::run_in_thread_with_globals<rustc_interface[c2746bee48761670]::util::run_in_thread_pool_with_globals<rustc_interface[c2746bee48761670]::interface::run_compiler<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#1} as core[30be359c16b30868]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7fdfb3598735 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h99757397e7c4fa77
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2015:9
  36:     0x7fdfb3598735 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7e0e3d311e6447da
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2015:9
  37:     0x7fdfb3598735 - std::sys::pal::unix::thread::Thread:🆕:thread_start::h0eb0f22e3002fa19
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys/pal/unix/thread.rs:108:17
  38:     0x7fdfb33839eb - <unknown>
  39:     0x7fdfb34077cc - <unknown>
  40:                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.78.0-nightly (af88f7db5 2024-02-08) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `range_shadow_lit::{closure#0}`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

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