Skip to content

broken mir, trivial loop with -Zvalidate-mir #73860

Closed

Description

@matthiaskrgr

Code

The code fails to pass -Zvalidate-mir

fn main() {
 for _ in &[0] {}
}

Meta

Repo is at c86039b

Error output

error: internal compiler error: broken MIR in Item(DefId(0:3 ~ main[317d]::main[0])) (input to phase Const) at bb13[0]:
encountered `Assign` statement with incompatible types:
left-hand side has type: !
right-hand side has type: ()
 --> main.rs:2:2
  |
2 |  for _ in &[0] {}
  |  ^^^^^^^^^^^^^^^^
  |
  = note: delayed at src/librustc_mir/transform/validate.rs:140:36

error: internal compiler error: broken MIR in Item(DefId(0:3 ~ main[317d]::main[0])) (after CheckPackedRef in phase Const) at bb13[0]:
encountered `Assign` statement with incompatible types:
left-hand side has type: !
right-hand side has type: ()
 --> main.rs:2:2
  |
2 |  for _ in &[0] {}
  |  ^^^^^^^^^^^^^^^^
  |
  = note: delayed at src/librustc_mir/transform/validate.rs:140:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:367:17
Backtrace

error: internal compiler error: broken MIR in Item(DefId(0:3 ~ main[317d]::main[0])) (input to phase Const) at bb13[0]:
encountered `Assign` statement with incompatible types:
left-hand side has type: !
right-hand side has type: ()
 --> main.rs:2:2
  |
2 |  for _ in &[0] {}
  |  ^^^^^^^^^^^^^^^^
  |
  = note: delayed at src/librustc_mir/transform/validate.rs:140:36

error: internal compiler error: broken MIR in Item(DefId(0:3 ~ main[317d]::main[0])) (after CheckPackedRef in phase Const) at bb13[0]:
encountered `Assign` statement with incompatible types:
left-hand side has type: !
right-hand side has type: ()
 --> main.rs:2:2
  |
2 |  for _ in &[0] {}
  |  ^^^^^^^^^^^^^^^^
  |
  = note: delayed at src/librustc_mir/transform/validate.rs:140:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:367:17
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /home/matthias/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /home/matthias/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:217
  10: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at ./src/liballoc/boxed.rs:1092
  11: rustc_driver::report_ice
             at src/librustc_driver/lib.rs:1160
  12: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:524
  13: std::panicking::begin_panic
             at ./src/libstd/panicking.rs:450
  14: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
             at src/librustc_errors/lib.rs:367
  15: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  16: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  17: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  18: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  19: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  20: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  21: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  22: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  23: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
             at ./src/liballoc/rc.rs:1159
  24: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  25: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  26: core::mem::drop
             at ./src/libcore/mem/mod.rs:877
  27: rustc_interface::interface::run_compiler_in_existing_thread_pool::{{closure}}::{{closure}}
             at ./src/librustc_interface/interface.rs:199
  28: rustc_data_structures::profiling::TimingGuard::run
             at ./src/librustc_data_structures/profiling.rs:555
  29: rustc_interface::interface::run_compiler_in_existing_thread_pool::{{closure}}
             at ./src/librustc_interface/interface.rs:199
  30: rustc_span::with_source_map
             at ./src/librustc_span/lib.rs:727
  31: rustc_interface::interface::run_compiler_in_existing_thread_pool
             at ./src/librustc_interface/interface.rs:189
  32: rustc_interface::interface::run_compiler::{{closure}}
             at ./src/librustc_interface/interface.rs:211
  33: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}
             at ./src/librustc_interface/util.rs:149
  34: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  35: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}
             at ./src/librustc_interface/util.rs:145
  36: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  37: rustc_ast::attr::with_globals::{{closure}}
             at ./src/librustc_ast/attr/mod.rs:44
  38: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  39: rustc_ast::attr::with_globals
             at ./src/librustc_ast/attr/mod.rs:44
  40: rustc_interface::util::spawn_thread_pool::{{closure}}
             at ./src/librustc_interface/util.rs:144
  41: rustc_interface::util::scoped_thread::{{closure}}
             at ./src/librustc_interface/util.rs:119
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.46.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z validate-mir

query stack during panic:
end of query stack

Activity

  1. added
    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.
    on Jun 29, 2020
  2. changed the title [-]broken mir, trivial loop with -Zverify-mir[/-] [+]broken mir, trivial loop with -Zvalidate-mir[/+] on Jun 29, 2020
  3. added
    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Jun 29, 2020
  4. RalfJung commented on Jun 30, 2020

    @RalfJung
    Member

    Oh that is interesting:

    left-hand side has type: !
    right-hand side has type: ()
    

    @nikomatsakis @eddyb is that expected? The other way around would make sense (assigning a ! into anything, really), but with a ! on the left, that seems odd? Or maybe the message just gets the sides wrong.

  5. RalfJung commented on Jun 30, 2020

    @RalfJung
    Member

    Yeah, that MIR looks really broken:

        let mut _14: !;                      // in scope 0 at test.rs:2:2: 2:18
    [...]
            _14 = const ();                  // scope 2 at test.rs:2:2: 2:18
    

    Cc @matthewjasper

  6. matthewjasper commented on Jun 30, 2020

    @matthewjasper
    Contributor

    This is probably due to this line:

    this.cfg.push_assign_unit(block, source_info, destination, this.hir.tcx());

    Break, Continueand Return shouldn't have this, since they have type !, not ().

  7. nagisa commented on Jul 4, 2020

    @nagisa
    Member

    is that expected? The other way around would make sense (assigning a ! into anything, really), but with a ! on the left, that seems odd? Or maybe the message just gets the sides wrong.

    This is a super old issue going back all the way to the initial MIR implementation and I’m somewhat confident is documented somewhere, though I cannot find an issue for this.

    IIRC these invalid assignments only happen in unreachable basic blocks, so however wrong it looks in isolation, it is dead code and I think it never was a priority to fix either generation or the MIR validation we had back then for exactly that reason.

    Looks like -Zvalidate-mir is a new take on validation? Perhaps the easy fix would be to not validate unreachable blocks.

  8. added 2 commits that reference this issue on Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-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.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions