Skip to content

Unexpected borrow checker ICE #57989

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
smikims opened this issue Jan 30, 2019 · 2 comments
Closed

Unexpected borrow checker ICE #57989

smikims opened this issue Jan 30, 2019 · 2 comments
Assignees
Labels
A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ NLL-sound Working towards the "invalid code does not compile" goal P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@smikims
Copy link

smikims commented Jan 30, 2019

Error message

Function it was working on when it crashed (apologies, this is in the middle of a refactor so it's a mess; I can provide more context or try to boil it down if needed):

    unsafe fn draw(&self) {
        let color_alg: &Fn(Complex, usize) -> usize = if (self.power - 2.0).abs() < 0.01 {
            &|c, i| self.get_color(c, i)
        } else {
            &|c, i| self.get_color_generic(c, i)
        };
        self.height = if !stdscr.is_null() {
            i32::from((*stdscr)._maxy) + 1i32
        } else {
            -1i32
        };
        self.width = if !stdscr.is_null() {
            i32::from((*stdscr)._maxx) + 1i32
        } else {
            -1i32
        };
        let mut i: i32 = 0i32;
        loop {
            if i >= self.height {
                break;
            }
            let mut j: i32 = 0i32;
            loop {
                if j >= self.width {
                    break;
                }
                if wmove(stdscr, i, j) != -1i32 {
                    waddch(
                        stdscr,
                        usize::from(self.colors[usize::from(color_alg(self.complex_value(i, j), self.iter))]),
                    );
                }
                j += 1;
            }
            i += 1;
        }
        wrefresh(stdscr);
    }
@jonas-schievink

This comment has been minimized.

@jonas-schievink jonas-schievink added 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. C-bug Category: This is a bug. A-borrow-checker Area: The borrow checker labels Jan 30, 2019
@smikims
Copy link
Author

smikims commented Jan 30, 2019

Just narrowed it down as far as I can; in this example the assignment to self.x must come before the call to g() and f() must take &self, not &mut self. Also, this only happens with the --edition=2018 flag.

struct A {
    x: i32,
}

impl A {
    fn f(&self) {
        let g = &|| self.f();
        self.x = 0;
        g();
    }
}

fn main() {}

This results in the following error message (now on the latest nightly):

error: internal compiler error: src/librustc_mir/borrow_check/places_conflict.rs:220: Tracking borrow behind shared reference.

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:605:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:482
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc_mir::borrow_check::places_conflict::unroll_place
  15: rustc_mir::borrow_check::places_conflict::unroll_place
  16: rustc_mir::borrow_check::places_conflict::unroll_place
  17: rustc_mir::borrow_check::places_conflict::unroll_place
  18: rustc_mir::dataflow::impls::borrows::Borrows::kill_borrows_on_place
  19: <rustc_mir::dataflow::impls::borrows::Borrows<'a, 'gcx, 'tcx> as rustc_mir::dataflow::BitDenotation<'tcx>>::statement_effect
  20: rustc_mir::dataflow::do_dataflow
  21: rustc_mir::borrow_check::do_mir_borrowck
  22: rustc::ty::context::GlobalCtxt::enter_local
  23: rustc_mir::borrow_check::mir_borrowck
  24: rustc::ty::query::__query_compute::mir_borrowck
  25: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_borrowck<'tcx>>::compute
  26: rustc::dep_graph::graph::DepGraph::with_task_impl
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  28: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners
  29: rustc::util::common::time
  30: <std::thread::local::LocalKey<T>>::with
  31: rustc::ty::context::TyCtxt::create_and_enter
  32: rustc_driver::driver::compile_input
  33: rustc_driver::run_compiler_with_pool
  34: <scoped_tls::ScopedKey<T>>::set
  35: rustc_driver::run_compiler
  36: <scoped_tls::ScopedKey<T>>::set
query stack during panic:
#0 [mir_borrowck] processing `A::f`
end of query stack
error: aborting due to previous error


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.34.0-nightly (c1c3c4e95 2019-01-29) running on x86_64-unknown-linux-gnu

Edit: You don't even need to say self.f(), all it needs is &|| self for the closure part.

@matthewjasper matthewjasper self-assigned this Jan 30, 2019
@matthewjasper matthewjasper added the A-NLL Area: Non-lexical lifetimes (NLL) label Jan 30, 2019
@oli-obk oli-obk added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Jan 30, 2019
@pnkfelix pnkfelix added P-high High priority NLL-sound Working towards the "invalid code does not compile" goal labels Jan 30, 2019
Centril added a commit to Centril/rust that referenced this issue Jan 30, 2019
… r=oli-obk

Pass correct arguments to places_conflict

The borrow place *must* be a place that we track borrows for, otherwise
we will likely ICE.

Closes rust-lang#57989
Centril added a commit to Centril/rust that referenced this issue Jan 30, 2019
… r=oli-obk

Pass correct arguments to places_conflict

The borrow place *must* be a place that we track borrows for, otherwise
we will likely ICE.

Closes rust-lang#57989
Centril added a commit to Centril/rust that referenced this issue Jan 31, 2019
… r=oli-obk

Pass correct arguments to places_conflict

The borrow place *must* be a place that we track borrows for, otherwise
we will likely ICE.

Closes rust-lang#57989
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ NLL-sound Working towards the "invalid code does not compile" goal P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants