Repository navigation
ICE when returning value bound by if let ... && let ... #99852
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn lambda() -> U {
let foo: Result<T, Error> = (...);
let baz: U = (...);
if let Ok(foo) = foo && let Ok(bar) = transform(foo) {
bar
} else {
baz
}
}
fn transform(input: T) -> Result<U, OtherError> {...}Meta
rustc --version --verbose:
rustc 1.64.0-nightly (6dbae3ad1 2022-07-25)
binary: rustc
commit-hash: 6dbae3ad19309bb541d9e76638e6aa4b5449f29a
commit-date: 2022-07-25
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6
Error output
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:77 ~ rustpsycle[b484]::get_image), const_param_did: None }) (end of phase transition to Optimized) at bb14[0]:
use of local _9, which has no storage here
--> src/lib.rs:30:2
|
30 | } else {
| ^
|
= note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:129:36
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1426:13
Backtrace
stack backtrace:
0: 0x7fcbc12a37d0 - std::backtrace_rs::backtrace::libunwind::trace::h74e6731adcfb8adc
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
1: 0x7fcbc12a37d0 - std::backtrace_rs::backtrace::trace_unsynchronized::h22bd7e644b454809
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7fcbc12a37d0 - std::sys_common::backtrace::_print_fmt::hec626af75cdf5d14
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/sys_common/backtrace.rs:66:5
3: 0x7fcbc12a37d0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hfe4102e485da4cf8
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/sys_common/backtrace.rs:45:22
4: 0x7fcbc12fda5c - core::fmt::write::h78ef6088ea150cd5
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/core/src/fmt/mod.rs:1198:17
5: 0x7fcbc1294eb5 - std::io::Write::write_fmt::hc440e7a0893fa000
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/io/mod.rs:1672:15
6: 0x7fcbc12a64a1 - std::sys_common::backtrace::_print::h6f08412e91897b34
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/sys_common/backtrace.rs:48:5
7: 0x7fcbc12a64a1 - std::sys_common::backtrace::print::he5a852bdc192e345
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/sys_common/backtrace.rs:35:9
8: 0x7fcbc12a64a1 - std::panicking::default_hook::{{closure}}::hf308fab78552e6c7
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/panicking.rs:295:22
9: 0x7fcbc12a6173 - std::panicking::default_hook::h66b19fed514ed5ed
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/panicking.rs:314:9
10: 0x7fcbc1b3ff44 - rustc_driver[45495022f976cfcf]::DEFAULT_HOOK::{closure#0}::{closure#0}
11: 0x7fcbc12a6c76 - std::panicking::rust_panic_with_hook::h9f418f85f12ababe
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/panicking.rs:702:17
12: 0x7fcbc2ced881 - std[9611d438937dc38]::panicking::begin_panic::<rustc_errors[65e8676031e39f89]::ExplicitBug>::{closure#0}
13: 0x7fcbc2ced5e6 - std[9611d438937dc38]::sys_common::backtrace::__rust_end_short_backtrace::<std[9611d438937dc38]::panicking::begin_panic<rustc_errors[65e8676031e39f89]::ExplicitBug>::{closure#0}, !>
14: 0x7fcbc2ce69d6 - std[9611d438937dc38]::panicking::begin_panic::<rustc_errors[65e8676031e39f89]::ExplicitBug>
15: 0x7fcbc2ce92f6 - std[9611d438937dc38]::panic::panic_any::<rustc_errors[65e8676031e39f89]::ExplicitBug>
16: 0x7fcbc45bc513 - <rustc_errors[65e8676031e39f89]::HandlerInner as core[807c2f8b07026ed8]::ops::drop::Drop>::drop
17: 0x7fcbc3cf0738 - core[807c2f8b07026ed8]::ptr::drop_in_place::<rustc_session[ee333364a5fb762c]::parse::ParseSess>
18: 0x7fcbc3cf2ce3 - <alloc[65bf4ccb0f73bc84]::rc::Rc<rustc_session[ee333364a5fb762c]::session::Session> as core[807c2f8b07026ed8]::ops::drop::Drop>::drop
19: 0x7fcbc3cd546d - core[807c2f8b07026ed8]::ptr::drop_in_place::<rustc_interface[21c2a0e765b4b7f4]::interface::Compiler>
20: 0x7fcbc3cd36a9 - rustc_span[ae34330c9831655e]::with_source_map::<core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>, rustc_interface[21c2a0e765b4b7f4]::interface::create_compiler_and_run<core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>, rustc_driver[45495022f976cfcf]::run_compiler::{closure#1}>::{closure#1}>
21: 0x7fcbc3cd7cb0 - rustc_interface[21c2a0e765b4b7f4]::interface::create_compiler_and_run::<core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>, rustc_driver[45495022f976cfcf]::run_compiler::{closure#1}>
22: 0x7fcbc3d03542 - <scoped_tls[315da7db807c9876]::ScopedKey<rustc_span[ae34330c9831655e]::SessionGlobals>>::set::<rustc_interface[21c2a0e765b4b7f4]::interface::run_compiler<core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>, rustc_driver[45495022f976cfcf]::run_compiler::{closure#1}>::{closure#0}, core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>>
23: 0x7fcbc3cd58bf - std[9611d438937dc38]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[21c2a0e765b4b7f4]::util::run_in_thread_pool_with_globals<rustc_interface[21c2a0e765b4b7f4]::interface::run_compiler<core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>, rustc_driver[45495022f976cfcf]::run_compiler::{closure#1}>::{closure#0}, core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>>::{closure#0}, core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>>
24: 0x7fcbc3cef9e9 - <<std[9611d438937dc38]::thread::Builder>::spawn_unchecked_<rustc_interface[21c2a0e765b4b7f4]::util::run_in_thread_pool_with_globals<rustc_interface[21c2a0e765b4b7f4]::interface::run_compiler<core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>, rustc_driver[45495022f976cfcf]::run_compiler::{closure#1}>::{closure#0}, core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>>::{closure#0}, core[807c2f8b07026ed8]::result::Result<(), rustc_errors[65e8676031e39f89]::ErrorGuaranteed>>::{closure#1} as core[807c2f8b07026ed8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
25: 0x7fcbc12b06c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h269b15882926c1ec
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/alloc/src/boxed.rs:1935:9
26: 0x7fcbc12b06c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h58323387bc1c2642
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/alloc/src/boxed.rs:1935:9
27: 0x7fcbc12b06c3 - std::sys::unix::thread::Thread::new::thread_start::h916fd4de50349453
at /rustc/6dbae3ad19309bb541d9e76638e6aa4b5449f29a/library/std/src/sys/unix/thread.rs:108:17
28: 0x7fcbc106cb43 - start_thread
at ./nptl/./nptl/pthread_create.c:442:8
29: 0x7fcbc10fea00 - clone3
at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
30: 0x0 - <unknown>
note: the compiler unexpectedly panicked. this is a bug.
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.64.0-nightly (6dbae3ad1 2022-07-25) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type dylib -C opt-level=3 -C embed-bitcode=no
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
est31 commentedon Jul 28, 2022
cc @c410-f3r
c410-f3r commentedon Jul 28, 2022
Code does not compile. Here goes a local attempt that was OK.
IFAICT,
compiler/rustc_const_eval/src/transform/validate.rsisn't very related tolet_chains.est31 commentedon Jul 28, 2022
@H2WO4 would it be possible to upload a self contained example that reproduces the issue?
Urgau commentedon Jul 28, 2022
It seams that the ICE only occurs with
opt-level>= 1 not below. Using the example from@c410-f3rI got a very similar ICE as the issue.H2WO4 commentedon Jul 28, 2022
This panics for me:
But removing the generic
Uinlambdaallows it to compile:H2WO4 commentedon Jul 28, 2022
Additionally, it still panics if we remove the generic
T:est31 commentedon Jul 28, 2022
Minimized:
c410-f3r commentedon Jul 28, 2022
From my playground tests, all the above snippets only happen in optimized ***** libraries *****.
I also couldn't reproduce locally using a slightly older compiler version (nightly-2022-07-15).
c410-f3r commentedon Jul 28, 2022
OK, just updated the compiler and the ICE happened. Since I've only worked in the parser these past weeks, it is possible that some recent MIR change caused this current behaviour.
est31 commentedon Jul 28, 2022
From that list, #98930 seems to be the most likely cause (edit: note this is just a guess).
10 remaining items
c410-f3r commentedon Aug 14, 2022
Hum, I see. Thanks!
c410-f3r commentedon Aug 25, 2022
Does not ICE any more after #100571. Test added in #100998.
c410-f3r commentedon Aug 26, 2022
Oooppsss... Sorry, this test still ICE.
Wasn't able to reproduce before but now it is known that the minimal compiler arguments are
--crate-type lib --emit=link -C opt-level=1.@H2WO4 Can you re-open?
apiraino commentedon Oct 4, 2022
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-high T-compiler
Rollup merge of rust-lang#104771 - est31:if_let_chain_broken_mir_test…
Rollup merge of rust-lang#104771 - est31:if_let_chain_broken_mir_test…
Auto merge of rust-lang#102394 - dingxiangfei2009:issue-102317, r=oli…