Skip to content

Extra type parameters make compiler panic calling Option::unwrap() on None #36708

Closed
@raviqqe

Description

@raviqqe

This works.

use std::ops::Div;

struct Foo(u64);

impl Div for Foo {
  type Output = Self;

  fn div(self, rhs: Self) -> Self::Output {
    Foo(0)
  }
}

fn main() {}

However, the code below doesn't because div has an extra parametric type T. But, the compiler doesn't emit proper error messages and says the compiler unexpectedly panicked. this is a bug..

use std::ops::Div;

struct Foo(u64);

impl Div for Foo {
  type Output = Self;

  fn div<T>(self, rhs: Self) -> Self::Output {
    Foo(0)
  }
}

fn main() {}

Error message

$ rustc main.rs
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                                                         

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:325
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Meta

$ rustc --version --verbose
rustc 1.13.0-nightly (4f9812a59 2016-09-21)
binary: rustc
commit-hash: 4f9812a59ab7247f0f52b01ca89b0793a2d289c3
commit-date: 2016-09-21
host: x86_64-unknown-linux-gnu
release: 1.13.0-nightly

Backtrace

$ RUST_BACKTRACE=1 rustc main.rs
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', ../src/libcore/option.rs:325
stack backtrace:
   1:     0x7fad5818a612 - std::sys::backtrace::tracing::imp::write::h4b09e6e8c01db097
   2:     0x7fad5819b42d - std::panicking::default_hook::{{closure}}::h1d3243f546573ff4
   3:     0x7fad5819887e - std::panicking::default_hook::h96c288d728df3ebf
   4:     0x7fad58198f68 - std::panicking::rust_panic_with_hook::hb1322e5f2588b4db
   5:     0x7fad58198e02 - std::panicking::begin_panic::hfbeda5aad583dc32
   6:     0x7fad58198d40 - std::panicking::begin_panic_fmt::h4fe9fb9d5109c4bf
   7:     0x7fad58198cc1 - rust_begin_unwind
   8:     0x7fad581e655c - core::panicking::panic_fmt::h4395919ece15c671
   9:     0x7fad581e648b - core::panicking::panic::hc74ff52ed78364e1
  10:     0x7fad5653534c - rustc_typeck::check::compare_method::compare_impl_method::h8b4c10d2a59ffd1f
  11:     0x7fad5654759f - rustc_typeck::check::check_impl_items_against_trait::h7d9aa9ff182ea156
  12:     0x7fad565452a8 - rustc_typeck::check::check_item_type::hb34d7fe10dce9af2
  13:     0x7fad5653eedb - <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item::hf0cba92c71ce3aaf
  14:     0x7fad56540b28 - rustc_typeck::check::check_item_types::hb459f0bcef68d00b
  15:     0x7fad565acdfe - rustc_typeck::check_crate::h56444fcd0efce52e
  16:     0x7fad58548941 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::hcac3a2328cd9259a
  17:     0x7fad5851599e - rustc_driver::driver::phase_3_run_analysis_passes::h9865057b323cad0e
  18:     0x7fad5850740a - rustc_driver::driver::compile_input::hc0edbed7edb3eb18
  19:     0x7fad58534d41 - rustc_driver::run_compiler::h22d678d32fb7c300
  20:     0x7fad5846e763 - std::panicking::try::do_call::h4d040997e2efdaf3
  21:     0x7fad581a3326 - __rust_maybe_catch_panic
  22:     0x7fad5848d7b9 - <F as alloc::boxed::FnBox<A>>::call_box::hba0b436c79e56b23
  23:     0x7fad581972d0 - std::sys::thread::Thread::new::thread_start::h022e3887023c6290
  24:     0x7fad503ad6f9 - start_thread
  25:     0x7fad57e58b5c - clone
  26:                0x0 - <unknown>

Metadata

Metadata

Assignees

Labels

I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions