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

'rustc' panicked at 'already borrowed: BorrowMutError' #41053

Closed
icorderi opened this issue Apr 4, 2017 · 4 comments
Closed

'rustc' panicked at 'already borrowed: BorrowMutError' #41053

icorderi opened this issue Apr 4, 2017 · 4 comments

Comments

@icorderi
Copy link
Contributor

icorderi commented Apr 4, 2017

I was going through some refactoring and the compiler exploded. No unsafe.

The last bits of code I was playing with can be found here, before I tried to refactor the example, the tests were building and passing.

The macro that might be to blame is here.

I tried this code:

I parked a branch with the code that made it blew up, you can find it here

cargo build works, cargo test blows up.

I expected to see this happen:

a happy compiler, worst case an unhappy one

Instead, this happened:

a dead compiler

Meta

rustc --version --verbose:

rustc 1.16.0 (30cf806ef 2017-03-10)
binary: rustc
commit-hash: 30cf806ef8881c41821fbd43e5cf3699c5290c16
commit-date: 2017-03-10
host: x86_64-apple-darwin
release: 1.16.0
LLVM version: 3.9

Backtrace:

thread 'rustc' panicked at 'already borrowed: BorrowMutError', /Users/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-mac/build/src/libcore/result.rs:868
stack backtrace:
   1:        0x108f4aa1c - std::sys::imp::backtrace::tracing::imp::write::h21ca2762819c7ae8
   2:        0x108f5737e - std::panicking::default_hook::{{closure}}::h38f99a37d00bb19b
   3:        0x108f56f23 - std::panicking::default_hook::ha2186ee24b50729c
   4:        0x108f57837 - std::panicking::rust_panic_with_hook::h979db19ee91d2a53
   5:        0x108f576e4 - std::panicking::begin_panic::h6a69f5b54391c64d
   6:        0x108f57602 - std::panicking::begin_panic_fmt::h9de2343580b3c2c4
   7:        0x108f57567 - rust_begin_unwind
   8:        0x108f95050 - core::panicking::panic_fmt::haa2997386017a96f
   9:        0x10570a3fe - core::result::unwrap_failed::ha64c7d5234009164
  10:        0x10578cb13 - rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore<'tcx> for rustc_metadata::cstore::CStore>::visible_parent_map::h3debf1ab33a226ab
  11:        0x105f2bb1f - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  12:        0x105f782f7 - rustc::util::ppaux::parameterized::h5f0560c5c9122355
  13:        0x108f974f5 - core::fmt::write::ha018cebab551510b
  14:        0x108f5ab8e - collections::fmt::format::he22202c7e3fef8be
  15:        0x105f2c9d4 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_impl_path::hcef2fff273c5fb99
  16:        0x105f2bf7f - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  17:        0x105f2bec8 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  18:        0x105f2bec8 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  19:        0x105f2bec8 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  20:        0x105f2c19a - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  21:        0x105f782f7 - rustc::util::ppaux::parameterized::h5f0560c5c9122355
  22:        0x108f974f5 - core::fmt::write::ha018cebab551510b
  23:        0x108f5ab8e - collections::fmt::format::he22202c7e3fef8be
  24:        0x105f2cb2f - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_impl_path::hcef2fff273c5fb99
  25:        0x105f2bf7f - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  26:        0x105f2bec8 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  27:        0x105f2bec8 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  28:        0x105f782f7 - rustc::util::ppaux::parameterized::h5f0560c5c9122355
  29:        0x105f7f685 - rustc::util::ppaux::<impl core::fmt::Display for rustc::ty::sty::TypeVariants<'tcx>>::fmt::h8dbc857add4c3d52
  30:        0x108f974f5 - core::fmt::write::ha018cebab551510b
  31:        0x108f984bd - core::fmt::Formatter::write_fmt::hd0523bf23d71b9a7
  32:        0x105d5d9b3 - <&'a T as core::fmt::Display>::fmt::h37b28e0776dc9105
  33:        0x108f974f5 - core::fmt::write::ha018cebab551510b
  34:        0x108f5ab8e - collections::fmt::format::he22202c7e3fef8be
  35:        0x105f2c9d4 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_impl_path::hcef2fff273c5fb99
  36:        0x105f2bf7f - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  37:        0x105f2bec8 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::push_item_path::h370e4c2bf96f903f
  38:        0x105f2b8a7 - rustc::ty::item_path::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::item_path_str::h234c98dec3818149
  39:        0x10550fb3f - <rustc_mir::transform::deaggregator::Deaggregator as rustc::mir::transform::MirPass<'tcx>>::run_pass::hac6be77ad6e60b6e
  40:        0x104de07d6 - <T as rustc::mir::transform::MirMapPass<'tcx>>::run_pass::ha077346e0b625917
  41:        0x105ebde61 - rustc::mir::transform::Passes::run_passes::h5259fd2d98400f5c
  42:        0x104e4be57 - rustc_driver::driver::phase_4_translate_to_llvm::{{closure}}::hed3481448c2f5eb6
  43:        0x104e4aa7d - rustc_driver::driver::phase_4_translate_to_llvm::h5f360db053c07be7
  44:        0x104e198d5 - rustc_driver::driver::compile_input::{{closure}}::h15150c478a98e9f1
  45:        0x104e4962f - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h9e118a56f5957bd6
  46:        0x104e28367 - rustc_driver::driver::phase_3_run_analysis_passes::h0569f99df4eb53d4
  47:        0x104e17a90 - rustc_driver::driver::compile_input::hb50de2aa3bf90e59
  48:        0x104e5f48e - rustc_driver::run_compiler::h4b71cb0b28ba1b4a
  49:        0x104d76ff8 - std::panicking::try::do_call::h7cd9045c0206869e
  50:        0x108f5a44a - __rust_maybe_catch_panic
  51:        0x104d9f913 - <F as alloc::boxed::FnBox<A>>::call_box::hca1d0347a9530a7f
  52:        0x108f564a4 - std::sys::imp::thread::Thread::new::thread_start::hca57ad22492f366f
  53:     0x7fffbc8fbaaa - _pthread_body
  54:     0x7fffbc8fb9f6 - _pthread_start
@arielb1
Copy link
Contributor

arielb1 commented Apr 4, 2017

Minimal example:
foo.rs:

pub trait Trait { fn foo(&self) {} }
pub struct Foo;

impl Iterator for Foo {
    type Item = ();
    fn next(&mut self) -> Option<()> {
        extern crate bar;
        impl ::Trait for bar::S {
            fn foo(&self) {}
        }
        None
    }
}

bar.rs

#![crate_type="rlib"]
pub struct S;

@icorderi
Copy link
Contributor Author

icorderi commented Apr 4, 2017

Thanks @arielb1, that was a quick fix.
Do you have a workaround until the fix makes it to master?

@arielb1
Copy link
Contributor

arielb1 commented Apr 4, 2017

@icorderi

The ICE occurs when you have an item referenced in an impl signature is imported from an extern crate statement occurs within an impl.

To work around the ICE, you can move the call to parse_params! to a different free function.

@icorderi
Copy link
Contributor Author

icorderi commented Apr 4, 2017

Got it, it works 👍, thanks!

icorderi added a commit to icorderi/tokio-jsonrpc that referenced this issue Apr 4, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 7, 2017
cstore: return an immutable borrow from `visible_parent_map`

This prevents an ICE when `visible_parent_map` is called multiple times, for example when an item referenced in an impl signature is imported from an  `extern crate` statement occurs within an impl.

Fixes rust-lang#41053.

r? @eddyb
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 7, 2017
cstore: return an immutable borrow from `visible_parent_map`

This prevents an ICE when `visible_parent_map` is called multiple times, for example when an item referenced in an impl signature is imported from an  `extern crate` statement occurs within an impl.

Fixes rust-lang#41053.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants