Skip to content

ICE calling unimplemented prelude trait methods. #19692

Closed
@orodley

Description

@orodley

The following (invalid) code triggers an ICE:

struct Foo;

fn ice(x: Foo) {
    let Some(ref y) = Some(x.nonexistent_method());
    y.clone();
}

fn main() { }

The same error occurs when replacing clone with some other methods from prelude traits with similar signatures - to_c_str or into_string for example.

However, if I declare my own trait with a similar method, e.g.: trait Bar { fn bar(&self) -> Self; }, and then replace the method call with a call to bar, there is an identical error message, but no ICE.

Removing either the Some or the ref makes the ICE disappear.

Compiler output:

$ RUST_BACKTRACE=1 rustc ice.rs
ice.rs:4:30: 4:50 error: type `Foo` does not implement any method in scope named `nonexistent_method`
ice.rs:4     let Some(ref y) = Some(x.nonexistent_method());
                                      ^~~~~~~~~~~~~~~~~~~~
ice.rs:5:7: 5:14 error: the type of this value must be known in this context
ice.rs:5     y.clone();
               ^~~~~~~
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' panicked at 'assertion failed: `(left == right) && (right == left)` (left: `None`, right: `Some(())`)', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/librustc_typeck/check/method/confirm.rs:153

stack backtrace:
   1:     0x7f5b9805ae50 - rt::backtrace::imp::write::hf87c140cfcd95fbaBly
   2:     0x7f5b9805e0a0 - failure::on_fail::h343c4b97464b676eZNy
   3:     0x7f5b97cb0fa0 - unwind::begin_unwind_inner::hb4b9831d2f5e86936Qc
   4:     0x7f5b97cb0bd0 - unwind::begin_unwind_fmt::h5c8826b0094c4275hOc
   5:     0x7f5b9717e800 - check::method::confirm::ConfirmContext<'a, 'tcx>::confirm::hb8176eb56afef6ceTxf
   6:     0x7f5b972622e0 - check::check_expr_with_unifier::check_method_call::h7dd70ab5683f061e9mo
   7:     0x7f5b972586a0 - check::check_expr_with_unifier::he91bcac7bd1c6fffYho
   8:     0x7f5b97213a40 - check::check_block_with_expected::h31910f8cb7bf5a4dBhq
   9:     0x7f5b971e7e20 - check::check_fn::h70c5e5169de64720PJk
  10:     0x7f5b97210c00 - check::check_bare_fn::h3f9ce32de12dd011Tyk
  11:     0x7f5b97208cd0 - check::check_item::h63605613fc52aeb74Sk
  12:     0x7f5b975518b0 - check_crate::closure.42937
  13:     0x7f5b9754f630 - util::common::time::h1247083444027210014
  14:     0x7f5b9754e900 - check_crate::h5e7941cca32a8446ASz
  15:     0x7f5b98495300 - driver::phase_3_run_analysis_passes::h63031984c677effauta
  16:     0x7f5b98484100 - driver::compile_input::h022976239e8f5a3cpba
  17:     0x7f5b98520d80 - run_compiler::h2b243518ea560709z4b
  18:     0x7f5b98520c70 - run::closure.21242
  19:     0x7f5b98532670 - task::TaskBuilder::try_future::closure.22690
  20:     0x7f5b98033410 - task::TaskBuilder::spawn_internal::closure.31179
  21:     0x7f5b97caed70 - task::Task::spawn::closure.5765
  22:     0x7f5b97d0c280 - rust_try_inner
  23:     0x7f5b97d0c270 - rust_try
  24:     0x7f5b97caee50 - unwind::try::ha36bc8815a761f13pFc
  25:     0x7f5b97caec10 - task::Task::run::h24525a73fb4c9bb3fOb
  26:     0x7f5b97cae800 - task::Task::spawn::closure.5741
  27:     0x7f5b97cb0250 - thread::thread_start::ha943fdda31374bc3i6b
  28:     0x7f5b92b9ffe0 - start_thread
  29:     0x7f5b97975c99 - __clone
  30:                0x0 - <unknown>

This occurs under:

$ uname -a
Linux <hostname> 3.16.0-4-amd64 #1 SMP Debian 3.16.7-2 (2014-11-06) x86_64 GNU/Linux
$ rustc --version=verbose
rustc 0.13.0-nightly (8bca470c5 2014-12-08 00:12:30 +0000)
binary: rustc
commit-hash: 8bca470c5acf13aa20022a2c462a89f72de721fc
commit-date: 2014-12-08 00:12:30 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions