Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

MIR-borrowck: ICE: this path should not cause illegal move #45694

Closed
arielb1 opened this issue Nov 1, 2017 · 0 comments
Closed

MIR-borrowck: ICE: this path should not cause illegal move #45694

arielb1 opened this issue Nov 1, 2017 · 0 comments
Labels
A-borrow-checker Area: The borrow checker

Comments

@arielb1
Copy link
Contributor

arielb1 commented Nov 1, 2017

MIR-borrowck: moves out of arrays and slices cause an ICE instead of a correct error. For example, this code (the compile-fail test E0508):

struct NonCopy;

fn main() {
    let array = [NonCopy; 1];
    let _value = array[0]; //~ ERROR E0508
}

Causes the following ICE with MIR borrowck:

error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Ast)
 --> e0509.rs:5:18
  |
5 |     let _value = array[0]; //~ ERROR E0508
  |                  ^^^^^^^^
  |                  |
  |                  cannot move out of here
  |                  help: consider using a reference instead: `&array[0]`

error: internal compiler error: rust://src/librustc_mir/util/borrowck_errors.rs:274: this path should not cause illegal move
 --> e0509.rs:5:18
  |
5 |     let _value = array[0]; //~ ERROR E0508
  |                  ^^^^^^^^

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.23.0-dev running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', rust://src/librustc_errors/lib.rs:450:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at rust://src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at rust://src/libstd/sys_common/backtrace.rs:69
   2: std::panicking::default_hook::{{closure}}
             at rust://src/libstd/sys_common/backtrace.rs:58
             at rust://src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at rust://src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at rust://src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at rust://src/libstd/panicking.rs:538
   6: rustc_errors::Handler::span_bug
             at ./<panic macros>:3
   7: rustc::session::opt_span_bug_fmt::{{closure}}
             at rust://src/librustc/session/mod.rs:980
   8: rustc::session::span_bug_fmt
             at rust://src/librustc/ty/context.rs:1538
             at rust://src/librustc/ty/context.rs:1527
             at rust://src/libstd/thread/local.rs:377
             at rust://src/libstd/thread/local.rs:288
             at rust://src/librustc/ty/context.rs:1523
             at rust://src/librustc/ty/context.rs:1538
             at rust://src/librustc/session/mod.rs:977
             at rust://src/librustc/session/mod.rs:970
   9: rustc_mir::util::borrowck_errors::BorrowckErrors::cannot_move_out_of_interior_noncopy
             at rust://src/librustc_mir/util/borrowck_errors.rs:274
  10: rustc_mir::borrow_check::mir_borrowck::{{closure}}
             at rust://src/librustc_mir/borrow_check.rs:83
  11: rustc_mir::borrow_check::mir_borrowck
             at rust://src/librustc/infer/mod.rs:375
             at rust://src/librustc/ty/context.rs:1511
             at rust://src/libstd/thread/local.rs:377
             at rust://src/libstd/thread/local.rs:288
             at rust://src/librustc/ty/context.rs:1508
             at rust://src/librustc/ty/context.rs:1319
             at rust://src/librustc/infer/mod.rs:375
             at rust://src/librustc_mir/borrow_check.rs:61
  12: rustc::dep_graph::graph::DepGraph::with_task_impl
             at rust://src/librustc/ty/maps/plumbing.rs:390
             at rust://src/librustc/dep_graph/graph.rs:287
  13: rustc::ty::maps::<impl rustc::ty::maps::queries::mir_borrowck<'tcx>>::force
             at rust://src/librustc/dep_graph/graph.rs:203
             at rust://src/librustc/ty/maps/plumbing.rs:442
             at rust://src/librustc_errors/lib.rs:566
             at rust://src/librustc/ty/maps/plumbing.rs:435
             at rust://src/librustc/ty/maps/plumbing.rs:130
             at rust://src/librustc/ty/maps/plumbing.rs:434
  14: rustc::ty::maps::<impl rustc::ty::maps::queries::mir_borrowck<'tcx>>::try_get
             at rust://src/librustc/ty/maps/plumbing.rs:313
             at rust://src/librustc/ty/maps/plumbing.rs:471
  15: rustc::ty::maps::TyCtxtAt::mir_borrowck
             at rust://src/librustc/ty/maps/plumbing.rs:510
  16: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_borrowck
             at rust://src/librustc/ty/maps/plumbing.rs:503
  17: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::{{closure}}
             at rust://src/librustc_driver/driver.rs:1095
  18: rustc::ty::context::TyCtxt::create_and_enter
             at rust://src/librustc/util/common.rs:120
             at rust://src/librustc_driver/driver.rs:1093
             at rust://src/librustc/ty/context.rs:1511
             at rust://src/libstd/thread/local.rs:377
             at rust://src/libstd/thread/local.rs:288
             at rust://src/librustc/ty/context.rs:1508
             at rust://src/librustc/ty/context.rs:1495
             at rust://src/libstd/thread/local.rs:377
             at rust://src/libstd/thread/local.rs:288
             at rust://src/librustc/ty/context.rs:1492
             at rust://src/librustc/ty/context.rs:1136
  19: rustc_driver::driver::compile_input
             at rust://src/librustc_driver/driver.rs:1041
             at rust://src/librustc_driver/driver.rs:210
  20: rustc_driver::run_compiler
             at rust://src/librustc_driver/lib.rs:252

It should be fixed to emit the same error as the AST.

@arielb1 arielb1 added WG-compiler-nll A-borrow-checker Area: The borrow checker labels Nov 1, 2017
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 14, 2017
…rielb1

MIR-borrowck: don't ICE for cannot move from array error

Closes rust-lang#45694
compile-fail test E0508 now gives
```text
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Ast)
  --> .\src\test\compile-fail\E0508.rs:18:18
   |
18 |     let _value = array[0];  //[ast]~ ERROR E0508
   |                  ^^^^^^^^
   |                  |
   |                  cannot move out of here
   |                  help: consider using a reference instead: `&array[0]`

error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Mir)
  --> .\src\test\compile-fail\E0508.rs:18:18
   |
18 |     let _value = array[0];  //[ast]~ ERROR E0508
   |                  ^^^^^^^^ cannot move out of here

error: aborting due to 2 previous errors
```
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 14, 2017
…rielb1

MIR-borrowck: don't ICE for cannot move from array error

Closes rust-lang#45694
compile-fail test E0508 now gives
```text
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Ast)
  --> .\src\test\compile-fail\E0508.rs:18:18
   |
18 |     let _value = array[0];  //[ast]~ ERROR E0508
   |                  ^^^^^^^^
   |                  |
   |                  cannot move out of here
   |                  help: consider using a reference instead: `&array[0]`

error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Mir)
  --> .\src\test\compile-fail\E0508.rs:18:18
   |
18 |     let _value = array[0];  //[ast]~ ERROR E0508
   |                  ^^^^^^^^ cannot move out of here

error: aborting due to 2 previous errors
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker
Projects
None yet
Development

No branches or pull requests

1 participant