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

ICE with unannotated literals #18954

Closed
r10r opened this issue Nov 14, 2014 · 5 comments · Fixed by #25344
Closed

ICE with unannotated literals #18954

r10r opened this issue Nov 14, 2014 · 5 comments · Fixed by #25344
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@r10r
Copy link

r10r commented Nov 14, 2014

[ruben@MacBook-Pro src]$ rustc --version=verbose
rustc 0.13.0-nightly (40fb87d40 2014-11-10 23:01:57 +0000)
binary: rustc
commit-hash: 40fb87d40f681f5356af42175fc7b85da387f037
commit-date: 2014-11-10 23:01:57 +0000
host: x86_64-apple-darwin
release: 0.13.0-nightly
trait Adder<Number> {
  fn sum(&self, summands: &[Number]) -> Number;
}

struct Calculator {
  foo: int,
}

impl Adder<int> for Calculator {

  fn sum(&self, summands: &[int]) -> int {
    println!("sum int");
    let mut result = 0i;
    for num in summands.iter() {
      result += *num;
    }
    result
  }
}

impl Adder<f32> for Calculator {

  fn sum(&self, summands: &[f32]) -> f32 {
    println!("sum f32");
    let mut result = 0f32;
    for num in summands.iter() {
      result += *num;
    }
    result
  }
}


fn main() {
  let calc = Calculator { foo: 4711 };
  println!("1 + 1 = {}", calc.sum([1,1].as_slice()));

  // raises the compiler error
  println!("1.0 + 2.3 = {}", calc.sum([1.0,2.3].as_slice()));
  // compiles and runs properly
  //println!("1.0 + 2.3 = {}", calc.sum([1.0f32,2.3f32].as_slice()));
}
error: internal compiler error: Impl DefId { krate: 0, node: 26 }:Calculator.Adder<int> was matchable against Obligation(trait_ref=<_ : Adder<_>>,depth=0) but now is not
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 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libsyntax/diagnostic.rs:175

stack backtrace:
   1:        0x11011e01f - rt::backtrace::imp::write::h37f6e30fade15cb76mt
   2:        0x1101211a7 - failure::on_fail::h4075de659ea4adb9VDt
   3:        0x1103a4415 - unwind::begin_unwind_inner::h9e12d6856ac2af42j1c
   4:        0x10e086757 - unwind::begin_unwind::h887212781071489879
   5:        0x10e086f93 - diagnostic::Handler::bug::he58e2d0573e8d5d4L5F
   6:        0x10d105271 - middle::traits::select::SelectionContext<'cx, 'tcx>::rematch_impl::h35320cfc53204d2fFbZ
   7:        0x10d0f3607 - middle::traits::select::SelectionContext<'cx, 'tcx>::confirm_candidate::hb7278faaf8bd08bdDRY
   8:        0x10d0ea1b7 - middle::traits::select::SelectionContext<'cx, 'tcx>::select::h20d24e63da941032znX
   9:        0x10d0e8e86 - middle::traits::fulfill::FulfillmentContext::select::h4f9eb03bbb3d4aa6gUW
  10:        0x10d0e8656 - middle::traits::fulfill::FulfillmentContext::select_where_possible::h212cad5c41e6ff5evTW
  11:        0x10d0014d2 - middle::traits::fulfill::FulfillmentContext::select_all_or_error::ha09a57d720916db7iRW
  12:        0x10d26dc78 - middle::typeck::check::vtable::select_all_fcx_obligations_or_error::h4291cb6f90f0ee15K7N
  13:        0x10d2c5ccb - middle::typeck::check::check_bare_fn::hec13c0cf792a848da8V
  14:        0x10d2c1e1d - middle::typeck::check::check_item::h7dd222d42ec19845jsW
  15:        0x10d2c5b10 - middle::typeck::check::check_item_types::hdbb49e408a7799c1k7V
  16:        0x10cdd1156 - util::common::time::h3942551398258420223
  17:        0x10d5d1eee - middle::typeck::check_crate::hcb0ab152bef1200chup
  18:        0x10d639d9f - driver::driver::phase_3_run_analysis_passes::hc02fc7265031485eIdC
  19:        0x10d634bd8 - driver::driver::compile_input::h2ba3685ec9df4f6btUB
  20:        0x10d6b23ed - driver::run_compiler::h6e93cd8bbb72fd50KKF
  21:        0x10d6b092e - driver::run::closure.146334
  22:        0x10cde940b - task::TaskBuilder<S>::try_future::closure.104770
  23:        0x10cde9303 - task::TaskBuilder<S>::spawn_internal::closure.104741
  24:        0x10cda27bd - task::NativeSpawner.Spawner::spawn::closure.2551
  25:        0x110402a0c - rust_try_inner
  26:        0x1104029f6 - rust_try
  27:        0x1103a1be7 - unwind::try::h009a35089a5882701Pc
  28:        0x1103a1a7c - task::Task::run::h4878cb7b665069bf61b
  29:        0x10cda25e3 - task::NativeSpawner.Spawner::spawn::closure.2475
  30:        0x1103a32a7 - thread::thread_start::h8e83ad43ae75daab3mc
  31:     0x7fff914642fc - _pthread_body
  32:     0x7fff91464279 - _pthread_body
@yuriks
Copy link
Contributor

yuriks commented Nov 16, 2014

rustc 0.13.0-nightly (d91a015ab 2014-11-14 23:37:27 +0000)
Here's another testcase for this bug:

trait Num {}

impl Num for i32 {}
impl Num for f32 {}

fn vec2s<T: Num>(a: T) {}

fn main() {
    // Removing either of these lines, or explicitly typing one of the literals stops the ICE from happening
    vec2s(0.0);
    vec2s(0);
}
error: internal compiler error: Impl DefId { krate: 0, node: 12 }:f32.Num was matchable against Obligation(trait_ref=<_ : Num>,depth=0) but now is not
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 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/diagnostic.rs:175

stack backtrace:
   1:     0x7f915ce993e0 - rt::backtrace::imp::write::h50b71c7573aa44d5Bgt
   2:     0x7f915ce9c460 - failure::on_fail::hc49a9332645beb08cCt
   3:     0x7f915d650c60 - unwind::begin_unwind_inner::hfe5348fa0e613e77E9c
   4:     0x7f915bdefa40 - unwind::begin_unwind::h2013521801281920279
   5:     0x7f915bdf01e0 - diagnostic::Handler::bug::h5ffb209701b06176C5F
   6:     0x7f915dd81300 - middle::traits::select::SelectionContext<'cx, 'tcx>::rematch_impl::h2e796c80b6b7b2d1RbZ
   7:     0x7f915dd6e380 - middle::traits::select::SelectionContext<'cx, 'tcx>::confirm_candidate::hcd9eb474da2b9af3PRY
   8:     0x7f915dd652c0 - middle::traits::select::SelectionContext<'cx, 'tcx>::select::hc07798a8a63189c7LnX
   9:     0x7f915dd63f30 - middle::traits::fulfill::FulfillmentContext::select::h38f1482e9e3d7175sUW
  10:     0x7f915deec9b0 - middle::typeck::check::vtable::select_new_fcx_obligations::h14c7bd91cbe892c8elO
  11:     0x7f915df81820 - middle::typeck::check::check_argument_types::h6b677199ffbdfaa2w4Y
  12:     0x7f915df83230 - middle::typeck::check::check_expr_with_unifier::h3fbf149ddd449935CDZ
  13:     0x7f915dfdcd30 - middle::typeck::check::check_stmt::h697d8a2a54580689zK1
  14:     0x7f915df47e50 - middle::typeck::check::check_block_with_expected::h4705ff96e614d629IO1
  15:     0x7f915df448e0 - middle::typeck::check::check_fn::he598dd4226ca32f92fW
  16:     0x7f915df44620 - middle::typeck::check::check_bare_fn::ha7a99d35a2a226a0h5V
  17:     0x7f915df40730 - middle::typeck::check::check_item::h6dc4c4f79498f002qpW
  18:     0x7f915df443e0 - middle::typeck::check::check_item_types::hae2bcc56566542e1r4V
  19:     0x7f915da3a4d0 - util::common::time::h9758243045951098006
  20:     0x7f915e2682d0 - middle::typeck::check_crate::he3aeb73f13b2d5c7lrp
  21:     0x7f915e2d0940 - driver::driver::phase_3_run_analysis_passes::h2dd06c2b56df9fc3M9B
  22:     0x7f915e2cb7d0 - driver::driver::compile_input::h0eb7d13e493860ffxQB
  23:     0x7f915e352fd0 - driver::run_compiler::hfef7578eee798d05OGF
  24:     0x7f915e352ec0 - driver::run::closure.146242
  25:     0x7f915da53d70 - task::TaskBuilder<S>::try_future::closure.104747
  26:     0x7f915da53b60 - task::TaskBuilder<S>::spawn_internal::closure.104718
  27:     0x7f915ebacb00 - task::NativeSpawner.Spawner::spawn::closure.2456
  28:     0x7f915d6a5bc0 - rust_try_inner
  29:     0x7f915d6a5bb0 - rust_try
  30:     0x7f915d64e5e0 - unwind::try::he984010f47153659mYc
  31:     0x7f915d64e470 - task::Task::run::had29636eca7af1a3u4b
  32:     0x7f915ebac840 - task::NativeSpawner.Spawner::spawn::closure.2382
  33:     0x7f915d64fc80 - thread::thread_start::h1833ce4dca7b1a7erpc
  34:     0x7f915868f250 - start_thread
  35:     0x7f915d32a3b9 - clone
  36:                0x0 - <unknown>

@huonw huonw added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Nov 16, 2014
@yuriks
Copy link
Contributor

yuriks commented Nov 16, 2014

It seems this bug is specifically triggered by using untyped literals, so perhaps the issue title should be changed.

@steveklabnik steveklabnik changed the title Compiler error when implementing generic trait twice with different type. ICE with unannotated literals Apr 21, 2015
@steveklabnik
Copy link
Member

can confirm this is still present in rustc 1.0.0-nightly (07560d233 2015-04-20) (built 2015-04-20)

@arielb1
Copy link
Contributor

arielb1 commented May 12, 2015

Yet another duplicate of #24352.

@alexcrichton
Copy link
Member

Thanks for finding all these duplicates @arielb1!

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

Successfully merging a pull request may close this issue.

6 participants