Skip to content

Compiler panic with "broken MIR in Item(WithOptConstParam { .. })" #87771

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ghost opened this issue Aug 4, 2021 · 2 comments · Fixed by #88451
Closed

Compiler panic with "broken MIR in Item(WithOptConstParam { .. })" #87771

ghost opened this issue Aug 4, 2021 · 2 comments · Fixed by #88451
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Aug 4, 2021

Code

fn main() {
    let mut arr = vec![vec![]];
    arr[0][0] = arr[0][0] = true;
}

Meta

Results in an ICE on both the latest nightly and stable versions:

rustc 1.56.0-nightly (a6ece5615 2021-08-03)
binary: rustc
commit-hash: a6ece56152d8eb11e049e9fcce147b2859e12c92
commit-date: 2021-08-03
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1

Error output

   Compiling play v0.1.0 (/tmp/play)
warning: Error finalizing incremental compilation session directory `/tmp/play/target/debug/incremental/play-26d7ofbz97wss/s-g141ls6r72-s5ddqo-working`: No such file or directory (os error 2)

error: internal compiler error[E0308]: mismatched types
 --> src/main.rs:3:17
  |
3 |     arr[0][0] = arr[0][1] = true;
  |                 ^^^^^^^^^^^^^^^^ expected `bool`, found `()`

error: internal compiler error: broken MIR in DefId(0:3 ~ play[8f25]::main) ((*_10) = const ()): bad assignment (bool = ()): NoSolution
 --> src/main.rs:3:5
  |
3 |     arr[0][0] = arr[0][1] = true;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:299:27

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:3 ~ play[8f25]::main), const_param_did: None }) (end of phase Optimization) at bb6[0]:
encountered `Assign(((*_10), const ()))` with incompatible types:
left-hand side has type: bool
right-hand side has type: ()
 --> src/main.rs:3:5
  |
3 |     arr[0][0] = arr[0][1] = true;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir/src/transform/validate.rs:121:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1050:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.56.0-nightly (a6ece5615 2021-08-03) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `play` (bin "play") generated 1 warning
error: could not compile `play`; 1 warning emitted
Backtrace

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1050:13
stack backtrace:
   0:     0x7f3eb028b6e0 - std::backtrace_rs::backtrace::libunwind::trace::h820df6e5a36600f2
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7f3eb028b6e0 - std::backtrace_rs::backtrace::trace_unsynchronized::h08422e102b839b36
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f3eb028b6e0 - std::sys_common::backtrace::_print_fmt::h57fa141da5c1d78f
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f3eb028b6e0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he771973a791a4e00
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f3eb02f97bc - core::fmt::write::h9a6d9c74526a6c1b
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/core/src/fmt/mod.rs:1117:17
   5:     0x7f3eb027cf25 - std::io::Write::write_fmt::h9d3df603db3c3ca4
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/io/mod.rs:1667:15
   6:     0x7f3eb028ed2b - std::sys_common::backtrace::_print::ha158db1ea88125c4
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f3eb028ed2b - std::sys_common::backtrace::print::h342dde07e263fe00
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f3eb028ed2b - std::panicking::default_hook::{{closure}}::h642e95a669718f6e
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/panicking.rs:208:50
   9:     0x7f3eb028e8a0 - std::panicking::default_hook::hc5055134d92c4284
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/panicking.rs:225:9
  10:     0x7f3eb0a6dd51 - rustc_driver::DEFAULT_HOOK::{{closure}}::{{closure}}::haff05a7eace0faae
  11:     0x7f3eb028f559 - std::panicking::rust_panic_with_hook::h6f45f3f96085621d
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/panicking.rs:627:17
  12:     0x7f3eb028f017 - std::panicking::begin_panic_handler::{{closure}}::h8cc693a35602cb15
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/panicking.rs:520:13
  13:     0x7f3eb028bbcc - std::sys_common::backtrace::__rust_end_short_backtrace::h89bf48eb2468d1e3
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7f3eb028ef79 - rust_begin_unwind
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/panicking.rs:516:5
  15:     0x7f3eb02585cb - std::panicking::begin_panic_fmt::h7b704e109b8f89ba
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/panicking.rs:458:5
  16:     0x7f3eb2ec7a49 - rustc_errors::HandlerInner::flush_delayed::h1214dd69c94464a0
  17:     0x7f3eb2ec64ad - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h99b093f7064b7696
  18:     0x7f3eb257c886 - core::ptr::drop_in_place<rustc_session::parse::ParseSess>::hf782bb3707a77e2d
  19:     0x7f3eb257e5fe - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h30c9788e90bfa607
  20:     0x7f3eb2552a6d - core::ptr::drop_in_place<rustc_interface::interface::Compiler>::h04cee182ac6141b7
  21:     0x7f3eb25521b3 - rustc_span::with_source_map::h8044517cb42f9e14
  22:     0x7f3eb2563f3a - rustc_interface::interface::create_compiler_and_run::h600b31664ea7498c
  23:     0x7f3eb2556099 - scoped_tls::ScopedKey<T>::set::h67b78cee48afc23b
  24:     0x7f3eb25525aa - std::sys_common::backtrace::__rust_begin_short_backtrace::h7d4575ab5f030af1
  25:     0x7f3eb25518e5 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0e7f7efed8d1ac6c
  26:     0x7f3eb029c1c7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he2a466339cf4c9af
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/alloc/src/boxed.rs:1572:9
  27:     0x7f3eb029c1c7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1f2d848478877ebe
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/alloc/src/boxed.rs:1572:9
  28:     0x7f3eb029c1c7 - std::sys::unix::thread::Thread::new::thread_start::h12773e412063ea14
                               at /rustc/a6ece56152d8eb11e049e9fcce147b2859e12c92/library/std/src/sys/unix/thread.rs:91:17
  29:     0x7f3eb01b5eae - start_thread
                               at /builddir/glibc-2.32/nptl/pthread_create.c:463:8
  30:     0x7f3eb00d42ff - __GI___clone
                               at /builddir/glibc-2.32/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  31:                0x0 - <unknown>

@ghost ghost added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 4, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Aug 12, 2021
@theo-lw
Copy link
Contributor

theo-lw commented Aug 28, 2021

I'd like to try tackling this :)

@theo-lw
Copy link
Contributor

theo-lw commented Aug 29, 2021

For reference, here's a smaller reproducible example.

Code

fn main() {
    let mut x;
    x = x = true;
}
Details

Meta

rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-unknown-linux-gnu
release: 1.51.0
LLVM version: 11.0.1

Error output

warning: variable `x` is assigned to, but never used
 --> main.rs:2:9
  |
2 |     let mut x;
  |         ^^^^^
  |
  = note: `#[warn(unused_variables)]` on by default
  = note: consider using `_x` instead

warning: value assigned to `x` is never read
 --> main.rs:3:5
  |
3 |     x = x = true;
  |     ^
  |
  = note: `#[warn(unused_assignments)]` on by default
  = help: maybe it is overwritten before being read?

warning: value assigned to `x` is never read
 --> main.rs:3:9
  |
3 |     x = x = true;
  |         ^
  |
  = help: maybe it is overwritten before being read?

warning: 3 warnings emitted

error: internal compiler error[E0308]: mismatched types
 --> main.rs:3:9
  |
3 |     x = x = true;
  |         ^^^^^^^^ expected `bool`, found `()`

error: internal compiler error: broken MIR in DefId(0:3 ~ main[317d]::main) (_1 = const ()): bad assignment (bool = ()): NoSolution
 --> main.rs:3:5
  |
3 |     x = x = true;
  |     ^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:249:27

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:3 ~ main[317d]::main), const_param_did: None }) (end of phase Optimization) at bb0[2]:
encountered `Assign((_1, const ()))` with incompatible types:
left-hand side has type: bool
right-hand side has type: ()
 --> main.rs:3:5
  |
3 |     x = x = true;
  |     ^^^^^^^^^^^^
  |
  = note: delayed at compiler/rustc_mir/src/transform/validate.rs:120:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:974:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.51.0 (2fd73fabe 2021-03-23) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

Backtrace

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:974:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/std/src/panicking.rs:435:5
   2: rustc_errors::HandlerInner::flush_delayed
   3: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   4: core::ptr::drop_in_place<rustc_session::parse::ParseSess>
   5: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
   6: core::ptr::drop_in_place<rustc_interface::interface::Compiler>
   7: rustc_span::with_source_map
   8: rustc_interface::interface::create_compiler_and_run
   9: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Manishearth added a commit to Manishearth/rust that referenced this issue Oct 4, 2021
Fix an ICE caused by type mismatch errors being ignored

This PR fixes rust-lang#87771. It turns out that the check on `compiler/rustc_typeck/src/check/demand.rs:148` leads to the ICE. I removed it because the early return in [`check_expr_assign`](https://github.com/theo-lw/rust/blob/dec7fc3ced5bc3c18d0e5d29921d087f93189cb8/compiler/rustc_typeck/src/check/expr.rs#L928) already prevents unnecessary error messages from the call to `check_expr_coercable_to_type`.
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 4, 2021
Fix an ICE caused by type mismatch errors being ignored

This PR fixes rust-lang#87771. It turns out that the check on `compiler/rustc_typeck/src/check/demand.rs:148` leads to the ICE. I removed it because the early return in [`check_expr_assign`](https://github.com/theo-lw/rust/blob/dec7fc3ced5bc3c18d0e5d29921d087f93189cb8/compiler/rustc_typeck/src/check/expr.rs#L928) already prevents unnecessary error messages from the call to `check_expr_coercable_to_type`.
@bors bors closed this as completed in a2c6075 Oct 4, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants