rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99k stars 12.79k forks source link

ICE : condition with std::f64::consts::PI #26334

Closed yasuyuky closed 9 years ago

yasuyuky commented 9 years ago

I tried this code:

use std::f64::consts::PI;

fn main() {
    let n = 1.5;
    if PI/3. < n && n < PI/2 {
        println!("PI/3<1.5<PI/2");
    }
}

And it causes internal compiler error

error: internal compiler error: Impl DefId { krate: 2, node: 26299 } was matchable against Obligation(predicate=Binder(TraitPredicate(core::ops::Div<_>)),depth=1) but now is not
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 'Box<Any>', /Users/yasuyuki/src/github.com/rust-lang/rust/src/libsyntax/diagnostic.rs:209

The right code is:

use std::f64::consts::PI;

fn main() {
    let n = 1.5;
    if PI/3. < n && n < PI/2. {
        println!("PI/3<1.5<PI/2");
    }
}

The following code is properly reported as error.

use std::f64::consts::PI;

fn main() {
    let n = 1.5;
    if PI/3 < n && n < PI/2 {
        println!("PI/3<1.5<PI/2");
    }
}
src/bug-reproduce-minimum.rs:5:8: 5:12 error: the trait `core::ops::Div<_>` is not implemented for the type `f64` [E0277]
src/bug-reproduce-minimum.rs:5     if PI/3 < n && n < PI/2 {
                                      ^~~~
src/bug-reproduce-minimum.rs:5:8: 5:12 error: the trait `core::ops::Div<_>` is not implemented for the type `f64` [E0277]
src/bug-reproduce-minimum.rs:5     if PI/3 < n && n < PI/2 {
                                      ^~~~
src/bug-reproduce-minimum.rs:5:24: 5:28 error: the trait `core::ops::Div<_>` is not implemented for the type `f64` [E0277]
src/bug-reproduce-minimum.rs:5     if PI/3 < n && n < PI/2 {
                                                      ^~~~
src/bug-reproduce-minimum.rs:5:24: 5:28 error: the trait `core::ops::Div<_>` is not implemented for the type `f64` [E0277]
src/bug-reproduce-minimum.rs:5     if PI/3 < n && n < PI/2 {
                                                      ^~~~

The following is also properly reported.

fn main() {
    let n = 1.5;
    if 3.14/3. < n && n < 3.14/2 {
        println!("PI/3<1.5<PI/2");
    }
}
src/bug-reproduce-minimum.rs:5:27: 5:33 error: the trait `core::ops::Div<i32>` is not implemented for the type `f64` [E0277]
src/bug-reproduce-minimum.rs:5     if 3.14/3. < n && n < 3.14/2 {
                                                         ^~~~~~
src/bug-reproduce-minimum.rs:5:27: 5:33 error: the trait `core::ops::Div<i32>` is not implemented for the type `f64` [E0277]
src/bug-reproduce-minimum.rs:5     if 3.14/3. < n && n < 3.14/2 {
                                                         ^~~~~~

Meta

rustc --version --verbose:

rustc 1.0.0-dev (a59de37e9 2015-05-13) (built 2015-05-27)
binary: rustc
commit-hash: a59de37e99060162a2674e3ff45409ac73595c0e
commit-date: 2015-05-13
build-date: 2015-05-27
host: x86_64-apple-darwin
release: 1.0.0-dev

Backtrace:

   1:        0x10bf9759f - sys::backtrace::write::hec7cfdc3cf53fd55t1r
   2:        0x10bf9fbd2 - panicking::on_panic::hc96d9a4346731de6tZv
   3:        0x10bf5c555 - rt::unwind::begin_unwind_inner::hcdf0005bcad4cbc4cHv
   4:        0x10b74788e - rt::unwind::begin_unwind::h1475597237717409057
   5:        0x10b748032 - diagnostic::Handler::bug::h84b85fb27fe1666dgwB
   6:        0x1096392bb - middle::traits::select::SelectionContext<'cx, 'tcx>::rematch_impl::h7ae9bc0ba3f307d8QXT
   7:        0x109638e48 - middle::infer::InferCtxt<'a, 'tcx>::commit_if_ok::h9896872441382966547
   8:        0x10962306d - middle::traits::select::SelectionContext<'cx, 'tcx>::confirm_candidate::h9ffdb9673d03f40eSfT
   9:        0x1096003c8 - middle::traits::select::SelectionContext<'cx, 'tcx>::select::hc650adc0ba04f166vhR
  10:        0x10960c2fd - middle::traits::project::project_type::hbf30aab62d3e93c4CYP
  11:        0x10960ae0b - middle::traits::project::opt_normalize_projection_type::h3bc953124c5ff6cceRP
  12:        0x10960757b - middle::traits::project::project_and_unify_type::h7c4b1244021c92238zP
  13:        0x10960581f - middle::infer::InferCtxt<'a, 'tcx>::commit_if_ok::h11358424279279309782
  14:        0x1095fda3d - middle::traits::fulfill::FulfillmentContext<'tcx>::select::ha1c162e872691582G9O
  15:        0x1095fd3b8 - middle::traits::fulfill::FulfillmentContext<'tcx>::select_where_possible::ha1b570f2a8a93e63U8O
  16:        0x108b78ff3 - check::vtable::select_fcx_obligations_where_possible::h2455e98717a3eb66r5b
  17:        0x108b98e61 - check::FnCtxt<'a, 'tcx>::resolve_type_vars_if_possible::haf93750958050dc9Vwo
  18:        0x108bfc758 - check::op::check_binop::h03830ccbac2ea609XMm
  19:        0x108c3b5ae - check::check_expr_with_unifier::h1846676654184666834
  20:        0x108bfc74d - check::op::check_binop::h03830ccbac2ea609XMm
  21:        0x108c3b5ae - check::check_expr_with_unifier::h1846676654184666834
  22:        0x108bfbece - check::op::check_binop::h03830ccbac2ea609XMm
  23:        0x108c3513b - check::check_expr_with_unifier::h13565443156412593619
  24:        0x108c2116d - check::check_expr_with_unifier::check_then_else::hbec39096da59a233xkq
  25:        0x108c3b88d - check::check_expr_with_unifier::h1846676654184666834
  26:        0x108c0ac4b - check::check_block_with_expected::he8a8060de04d30b8nUr
  27:        0x108bebed8 - check::check_fn::h50282556366a076dUGn
  28:        0x108c06035 - check::check_bare_fn::h96c3b9905631c8b9twn
  29:        0x108c04126 - check::CheckItemBodiesVisitor<'a, 'tcx>.Visitor<'tcx>::visit_item::hcdcc267b07fbc74cwtn
  30:        0x108cce5fa - check_crate::closure.38028
  31:        0x108cc9a07 - check_crate::h37d010016ad05ae7XcC
  32:        0x108a31884 - driver::phase_3_run_analysis_passes::h63bd1fe8e1faf57bnGa
  33:        0x108a1328c - driver::compile_input::h18cf61f496257266Qba
  34:        0x108adb953 - run_compiler::he7f3dd6158647d40z4b
  35:        0x108ad947a - boxed::F.FnBox<A>::call_box::h8093977037963349376
  36:        0x108ad8917 - rt::unwind::try::try_fn::h4891269637569629404
  37:        0x10c023fa8 - rust_try_inner
  38:        0x10c023f95 - rust_try
  39:        0x108ad8bf0 - boxed::F.FnBox<A>::call_box::h1987528937615105746
  40:        0x10bf9e71d - sys::thread::create::thread_start::h1434d98bff469646L4u
  41:     0x7fff995d7267 - _pthread_body
  42:     0x7fff995d71e4 - _pthread_start
jooert commented 9 years ago

Doesn't occur on nightly, probably fixed in #25344.

alexcrichton commented 9 years ago

Yay!

yasuyuky commented 9 years ago

Confirmed fixed in nightly. Thanks.