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

Panic on Option::unwrap inside rustc_typeck::check::compare_method::compare_const_impl #41549

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

Comments

@Ruin0x11
Copy link

I got an ICE after adding #![feature(associated_consts)] to a project and migrating to nightly. Would appreciate help.

   Compiling sabi v0.1.0 (file:///home/nuko/build/sabi)
     Running `rustc --crate-name sabi src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8ef730904cdb3202 -C extra-filename=-8ef730904cdb3202 --out-dir /home/nuko/build/sabi/target/debug/deps -L dependency=/home/nuko/build/sabi/target/debug/deps --extern lazy_static=/home/nuko/build/sabi/target/debug/deps/liblazy_static-18005fa1be5dd889.rlib --extern rustbox=/home/nuko/build/sabi/target/debug/deps/librustbox-0ce884825441c60e.rlib --extern chrono=/home/nuko/build/sabi/target/debug/deps/libchrono-6725d8b05e3d1a1e.rlib --extern enum_derive=/home/nuko/build/sabi/target/debug/deps/libenum_derive-571a57db87053f20.rlib --extern macro_attr=/home/nuko/build/sabi/target/debug/deps/libmacro_attr-8f0b61e973dcd6c1.rlib --extern backtrace=/home/nuko/build/sabi/target/debug/deps/libbacktrace-db0734c9c79848f2.rlib --extern goap=/home/nuko/build/sabi/target/debug/deps/libgoap-cae2f3d8a34a9aef.rlib --extern env_logger=/home/nuko/build/sabi/target/debug/deps/libenv_logger-ce278d65fff484a8.rlib --extern infinigen=/home/nuko/build/sabi/target/debug/deps/libinfinigen-95df6657b2a24fa0.rlib --extern serde=/home/nuko/build/sabi/target/debug/deps/libserde-46dd15ab79d4d223.rlib --extern slog=/home/nuko/build/sabi/target/debug/deps/libslog-eea2cd42d168e09d.rlib --extern slog_stream=/home/nuko/build/sabi/target/debug/deps/libslog_stream-738219c3754c3ec3.rlib --extern calx_ecs=/home/nuko/build/sabi/target/debug/deps/libcalx_ecs-c3b37e6a0ec71fa3.rlib --extern tcod=/home/nuko/build/sabi/target/debug/deps/libtcod-fa9483bd403fbbc0.rlib --extern toml=/home/nuko/build/sabi/target/debug/deps/libtoml-fb537ab82d6cf526.rlib --extern bitflags=/home/nuko/build/sabi/target/debug/deps/libbitflags-40c9799a6d297c75.rlib --extern uuid=/home/nuko/build/sabi/target/debug/deps/libuuid-9c058fc6aef3689f.rlib --extern rand=/home/nuko/build/sabi/target/debug/deps/librand-76456d761c2cb637.rlib --extern serde_derive=/home/nuko/build/sabi/target/debug/deps/libserde_derive-583ac15462b70281.so -L /home/nuko/build/sabi/target/debug/build/termbox-sys-679ef25ef47d21c5/out/lib -L native=/home/nuko/build/sabi/target/debug/build/backtrace-sys-1b1714f3e656f8c7/out/.libs -L native=/home/nuko/build/sabi/target/debug/build/miniz-sys-07cc64aa136ffbd3/out -L native=/home/nuko/build/sabi/target/debug/build/tcod-sys-7ff280fd359ac283/out -L native=/usr/lib -L native=/usr/lib -L native=/usr/lib -L /home/nuko/build/sabi/target/debug/build/tcod-sys-7ff280fd359ac283/out`
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 'called `Option::unwrap()` on a `None` value', /checkout/src/libcore/option.rs:329
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:355
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:365
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:549
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:511
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:495
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:471
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:69
   9: core::panicking::panic
             at /checkout/src/libcore/panicking.rs:49
  10: rustc_typeck::check::compare_method::compare_const_impl
  11: rustc_typeck::check::check_impl_items_against_trait
  12: rustc_typeck::check::check_item_type
  13: rustc_typeck::check::check_item_types
  14: rustc_typeck::check_crate
  15: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  16: rustc_driver::driver::phase_3_run_analysis_passes
  17: rustc_driver::driver::compile_input
  18: rustc_driver::run_compiler
  19: std::panicking::try::do_call
  20: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:98
  21: <F as alloc::boxed::FnBox<A>>::call_box
  22: std::sys::imp::thread::Thread::new::thread_start
             at /checkout/src/liballoc/boxed.rs:650
             at /checkout/src/libstd/sys_common/thread.rs:21
             at /checkout/src/libstd/sys/unix/thread.rs:84
  23: start_thread
  24: clone

$ rustc --version
rustc 1.18.0-nightly (2b4c91158 2017-04-25)

This might be the call to unwrap that panics.

@Ruin0x11 Ruin0x11 changed the title Panic on Option::unwrap inside rustc_typeck::check::compare_method::compare_const_impl Panic on Option::unwrap inside rustc_typeck::check::compare_method::compare_const_impl Apr 26, 2017
@Ruin0x11
Copy link
Author

Ruin0x11 commented Apr 26, 2017

Also, the state of the code I was working on was such that I was implementing a trait with provided methods, but accidentally implementing over the provided methods and not providing all the required methods.

@Ruin0x11
Copy link
Author

Ruin0x11 commented Apr 26, 2017

Ok, the error was due to having the incorrect type on an associated constant:

// In library
pub trait ManagedChunk: Serialize + Deserialize {
    const SECTOR_SIZE: usize = 4096;

    const REGION_WIDTH: i32 = 16;
}

// ...

// In binary project
impl ManagedChunk for SerialChunk {
    const SECTOR_SIZE: u32 = 4096;

    const REGION_WIDTH: u32 = 16;
}

Fixing that makes the compiler panic go away.

But this example errors correctly on playground (nightly/debug):

#![feature(associated_consts)]

trait MyTrait: Clone {
    const MY_CONST: usize = 4096;
    const MY_OTHER_CONST: i32 = 16;
}

#[derive(Clone)]
struct Dude {
    
}

impl MyTrait for Dude {
    const MY_CONST: u32 = 4096;
    const MY_OTHER_CONST: u32 = 16;
}

fn main() {
    println!("{}", Dude::MY_CONST);
    println!("{}", Dude::MY_OTHER_CONST);
}

Output:

rustc 1.18.0-nightly (63c77214c 2017-04-24)
error[E0326]: implemented const `MY_CONST` has an incompatible type for trait
  --> <anon>:14:21
   |
4  |     const MY_CONST: usize = 4096;
   |                     ----- type in trait
...
14 |     const MY_CONST: u32 = 4096;
   |                     ^^^ expected usize, found u32

error[E0326]: implemented const `MY_OTHER_CONST` has an incompatible type for trait
  --> <anon>:15:27
   |
5  |     const MY_OTHER_CONST: i32 = 16;
   |                           --- type in trait
...
15 |     const MY_OTHER_CONST: u32 = 16;
   |                           ^^^ expected i32, found u32

error: aborting due to 2 previous errors

@sfackler sfackler added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 26, 2017
arielb1 added a commit to arielb1/rust that referenced this issue Apr 27, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 27, 2017
don't ICE on cross-crate associated const type mismatch

Fixes rust-lang#41549.

r? @eddyb
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 28, 2017
don't ICE on cross-crate associated const type mismatch

Fixes rust-lang#41549.

r? @eddyb
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 28, 2017
don't ICE on cross-crate associated const type mismatch

Fixes rust-lang#41549.

r? @eddyb
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 28, 2017
don't ICE on cross-crate associated const type mismatch

Fixes rust-lang#41549.

r? @eddyb
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 28, 2017
don't ICE on cross-crate associated const type mismatch

Fixes rust-lang#41549.

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

No branches or pull requests

2 participants