Skip to content
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

rustc internal compiler error: 'assertion failed: resolution.depth == 0 || resolution.base_def != Def::Err' #39559

Closed
lambdaxymox opened this issue Feb 5, 2017 · 2 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@lambdaxymox
Copy link

lambdaxymox commented Feb 5, 2017

I was experimenting with type-checked vector space (i.e. NOT Vec) operations in Rust, and I triggered a compiler panic using a nightly version of rustc. I reproduced it with the following minimal example.

trait Dim {
    fn dim() -> usize;
}

enum Dim3 {}

impl Dim for Dim3 {
    fn dim() -> usize {
        3
    }
}

pub struct Vector<T, D: Dim> {
    entries: [T; D::dim()]
}

fn main() {
    let array: [usize; Dim3::dim()] = [0; Dim3::dim()];
}

Using

$ rustc --version
rustc 1.15.0 (10893a9a3 2017-01-19)

gave me an error I basically expected

$ rustc panic.rs
error[E0080]: constant evaluation error
  --> panic.rs:26:18
   |
26 |     entries: [T; D::dim()]
   |                  ^^^^^^ unresolved path in constant expression

error: aborting due to previous error

but when I switched to rustc-nightly

$ rustup default nightly
$ rustc --version --verbose
rustc 1.17.0-nightly (0648517fa 2017-02-03)
binary: rustc
commit-hash: 0648517faf1e2cf37c8b6770cbd0180a816ed9a0
commit-date: 2017-02-03
host: x86_64-unknown-linux-gnu
release: 1.17.0-nightly
LLVM version: 3.9

I triggered the following compiler panic.

$ RUST_BACKTRACE=1 rustc panic.rs
error[E0402]: cannot use an outer type parameter in this context
  --> panic.rs:14:18
   |
14 |     entries: [T; D::dim()]
   |                  ^^^^^^

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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'assertion failed: resolution.depth == 0 || resolution.base_def != Def::Err', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_resolve/lib.rs:3057
stack backtrace:
   1:     0x7f6ce27e245c - std::sys::imp::backtrace::tracing::imp::write::hf7294f5e24536b4a
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7f6ce27f090e - std::panicking::default_hook::{{closure}}::h9a07d0b00c43fbee
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:351
   3:     0x7f6ce27f04b3 - std::panicking::default_hook::hf25feff2d08bf39b
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:361
   4:     0x7f6ce27f0dab - std::panicking::rust_panic_with_hook::h4cb8c6fbb8386ccf
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:555
   5:     0x7f6ce1c1f5df - std::panicking::begin_panic::hf1b80a6a0e51b6b9
   6:     0x7f6ce1cadab7 - rustc_resolve::Resolver::record_def::h15236138b24715a8
   7:     0x7f6ce1ca392f - rustc_resolve::Resolver::smart_resolve_path_fragment::h1fa53ba27ab9a109
   8:     0x7f6ce1ca323e - rustc_resolve::Resolver::smart_resolve_path::h13f47097f2a193db
   9:     0x7f6ce1cac5ec - rustc_resolve::Resolver::resolve_expr::hf3d20230b68f4493
  10:     0x7f6ce1cabdc2 - rustc_resolve::Resolver::resolve_expr::hf3d20230b68f4493
  11:     0x7f6ce1c92a99 - <rustc_resolve::Resolver<'a> as syntax::visit::Visitor<'tcx>>::visit_ty::hb5b693f9b7bbf593
  12:     0x7f6ce1c6c13a - syntax::visit::walk_item::h252471301ef1c7d3
  13:     0x7f6ce1c9d948 - rustc_resolve::Resolver::resolve_item::h2d1f35e3feef0866
  14:     0x7f6ce1c9629f - rustc_resolve::Resolver::resolve_crate::h17a2aa2bf4f16732
  15:     0x7f6ce2b7d7ec - rustc_driver::driver::phase_2_configure_and_expand::{{closure}}::h69863e9637c42976
  16:     0x7f6ce2b765a8 - rustc_driver::driver::phase_2_configure_and_expand::h026284537f8f8432
  17:     0x7f6ce2b6d37a - rustc_driver::driver::compile_input::hab977ae496b3a6f1
  18:     0x7f6ce2bb99c4 - rustc_driver::run_compiler::h81290683db66a63c
  19:     0x7f6ce2ac5deb - std::panicking::try::do_call::h00942d7a5d04424f
  20:     0x7f6ce27f9bea - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
  21:     0x7f6ce2aee052 - <F as alloc::boxed::FnBox<A>>::call_box::hd87f7ab2fccbd670
  22:     0x7f6ce27ef764 - std::sys::imp::thread::Thread::new::thread_start::hc16926852e47c008
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:623
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys_common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84
  23:     0x7f6cda5d6453 - start_thread
  24:     0x7f6ce24b27de - __GI___clone
  25:                0x0 - <unknown>

Ostensibly the error is expected but the panic is not. It seems to be something about the vector struct definition that's causing rustc to panic, because when I remove the vector code, the compiler panic goes away.

trait Dim {
    fn dim() -> usize;
}

enum Dim3 {}

impl Dim for Dim3 {
    fn dim() -> usize {
        3
    }
}
/*
pub struct Vector<T, D: Dim> {
    entries: [T; D::dim()]
}
*/
fn main() {
    let array: [usize; Dim3::dim()] = [0; Dim3::dim()];
}

Using the same rustc-nightly as before, the following happens.

$ rustc --version --verbose
rustc 1.17.0-nightly (0648517fa 2017-02-03)
// ...
$ rustc panic.rs
error[E0080]: constant evaluation error
  --> panic.rs:18:24
// ...
error: aborting due to 2 previous errors

as expected. Interestingly, rustc throws a different compiler error before it panics as well. I am not sure if that's relevant or not though.

@lambdaxymox lambdaxymox changed the title rustc compiler panic: 'assertion failed: resolution.depth == 0 || resolution.base_def != Def::Err' rustc internal compiler error: 'assertion failed: resolution.depth == 0 || resolution.base_def != Def::Err' Feb 5, 2017
@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 7, 2017
@jseyfried
Copy link
Contributor

cc @petrochenkov

@petrochenkov
Copy link
Contributor

@eddyb found this too (#38154 (comment)) and disabled the assert, but this should be preventively fixed somewhere in resolve_path instead, IMO.
(Added this to my work queue.)

bors added a commit that referenced this issue Feb 19, 2017
Fix two ICEs in path resolution

Fixes #39535
Fixes #39559
Fixes #39924

r? @eddyb
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants