Skip to content

[Nightly 1.4.0-4f33e43cb 2015-08-05] Compiler panic when mis-using Zero trait #27591

Closed

Description

Attempting to misuse a trait can cause a compiler panic. The offending code is a simplified version of what I was working on.

I tried this code:

fn rem_is_zero<T: Eq + Rem + Zero>(n: T, m: T) -> bool
  where <T as Rem>::Output: Zero + Eq
{
  let z = <T as Rem>::Output::zero(); // Compiler panic
  //let z = <<T as Rem>::Output as Zero>::zero(); // Compiles correctly

  (n % m) == z
}

After reviewing the documentation, I expect this to throw a syntax error. Specifically, because the let RHS should be written as: <<T as Rem>::Output as Zero>::zero. This code does compile and work as expected.

I don't know if this is specific to the Zero trait as I was able to use it like this:

fn eq_zero<T:Eq + Zero>(n: T) -> bool
{
  let z = T::zero();

  n == z
}

Meta

rustc --version --verbose:

rustc 1.4.0-nightly (4f33e43cb 2015-08-05)
binary: rustc
commit-hash: 4f33e43cbceb60ec85bb5140bd5470965ea92d16
commit-date: 2015-08-05
host: x86_64-pc-windows-gnu
release: 1.4.0-nightly

Backtrace:

C:\Stuff\Programming\rust-tut\rust-nightly-bug\src>rustc main.rs
main.rs:18:11: 18:35 error: internal compiler error: Type parameter `Self/SelfSpace.0` (Self/SelfSpace/0) out of range when substituting (root type=Some(Self)) substs=Substs[types=[[];[];[]], regions=[[];[];[]]]
main.rs:18   let z = <T as Rem>::Output::zero();
                     ^~~~~~~~~~~~~~~~~~~~~~~~
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 'Box<Any>', ../src/libsyntax\diagnostic.rs:176

stack backtrace:
   1:         0x699b9ce8 - sys::backtrace::write::h681b474c6c2394f4tNs
   2:         0x699c37ff - rt::unwind::register::hb538ab914c4328d5b2w
   3:         0x699854df - rt::unwind::begin_unwind_inner::hb80fd8ef51b4060akZw
   4:         0x7105ee5b - diagnostic::SpanHandler::span_bug::hc633dbf01b525dc5X6A
   5:         0x7105ee13 - diagnostic::SpanHandler::span_bug::hc633dbf01b525dc5X6A
   6:         0x692b88d8 - middle::subst::SubstFolder<'a, 'tcx>.TypeFolder<'tcx>::fold_ty::hca42f6dc71385de0GnQ
   7:         0x670f83d1 - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::ty_infer::hb1193da908738887xBo
   8:         0x6716d690 - rscope::ShiftedRscope<'r>.RegionScope::anon_regions::h419ad07efdb37e6bUlu
   9:         0x671752b2 - astconv::PathParamMode...std..cmp..PartialEq::ne::h94fa3bff02dd36c9OIu
  10:         0x67174689 - astconv::PathParamMode...std..cmp..PartialEq::ne::h94fa3bff02dd36c9OIu
  11:         0x6717a6cc - astconv::PathParamMode...std..cmp..PartialEq::ne::h94fa3bff02dd36c9OIu
  12:         0x671630d8 - check::TupleArgumentsFlag...std..clone..Clone::clone::hedb38ea352ace7f6cBq
  13:         0x67091969 - check::resolve_ty_and_def_ufcs::h0db529947a54cd24X2r
  14:         0x6715813b - check::may_break::he5881651fb8999a1eut
  15:         0x670f995e - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::h759a827f017a8a8atDo
  16:         0x67141285 - check::may_break::he5881651fb8999a1eut
  17:         0x67166240 - check::check_decl_initializer::hf0aa92b366271b1awas
  18:         0x671662da - check::check_decl_local::h37a43869df125d9bKbs
  19:         0x671664bf - check::check_stmt::h5078de71b85f2dc0Dds
  20:         0x671182fb - check::GatherLocalsVisitor<'a, 'tcx>.Visitor<'tcx>::visit_item::h6ba246b1c9f3850dKIn
  21:         0x670f920a - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::h759a827f017a8a8atDo
  22:         0x6710fa3c - check::check_item_types::h3739f0f18758ac32ewn
  23:         0x6710dcf0 - check::check_item_body::hc85a464b96f40859HYn
  24:         0x6710f684 - check::check_item_types::h3739f0f18758ac32ewn
  25:         0x671c8634 - check_crate::ha45cf61934d4de29laD
  26:         0x67be60dc - driver::assign_node_ids_and_map::h4dcd00430a00f2727Da
  27:         0x67be47f4 - driver::assign_node_ids_and_map::h4dcd00430a00f2727Da
  28:         0x67bdef86 - driver::assign_node_ids_and_map::h4dcd00430a00f2727Da
  29:         0x67bc2472 - driver::compile_input::h456239a0987e1d55Tba
  30:         0x67caa553 - run_compiler::ha97eef431fa5768cC7b
  31:         0x67ca8407 - run::h1e382076a350f7f7i7b
  32:         0x67ca7da9 - run::h1e382076a350f7f7i7b
  33:         0x699c318c - rt::unwind::imp::rust_eh_personality_catch::h8647fb0995b90ac0TMw
  34:         0x699ad7e2 - rt::unwind::try::inner_try::haade0eef5e14ff2ddVw
  35:         0x67ca7f77 - run::h1e382076a350f7f7i7b
  36:         0x699c157e - sys::process::Command::cwd::h322b10c2248cc4393Ev
  37:     0x7fffae6d2d92 - BaseThreadInitThunk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance 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