Closed
Description
Tried to find a simple example from my horrible scratch code, the code shouldn't compile due to the division of int and float but the compiler panics instead of erroring out.
I tried this code:
extern crate time;
fn main() {
let max = 10;
let mut total : f64 = 0.0;
for i in 1..max {
let start_time = time::precise_time_ns();
// operation here
let end_time = time::precise_time_ns();
let duration = (end_time - start_time) as f64 / 1000000.0;
println!("Time diff: {} ms", duration);
total += duration;
}
println!("Avg: {}", total / max);
}
I expected to see this happen: warning about the division such as:
error: the trait `core::ops::Div<_>` is not implemented for the type `f64` [E0277]
That error occurs if you remove the for loop.
Instead, this happened: rustc panicked
error: internal compiler error: Impl DefId { krate: 2, node: 42138 } 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>', C:/bot/slave/nightly-dist-rustc-win-64/build/src/libsyntax\diagnostic.rs:190
Meta
rustc --version --verbose
:
rustc 1.0.0-nightly (083b8a404 2015-04-05) (built 2015-04-05)
binary: rustc
commit-hash: 083b8a40413eb3dfec7430150b8895f6c8bbafca
commit-date: 2015-04-05
build-date: 2015-04-05
host: x86_64-pc-windows-gnu
release: 1.0.0-nightly
Backtrace:
stack backtrace:
1: 0x7120a6f3 - sys::backtrace::write::h44450b400aabf2c7DUC
2: 0x7121fc81 - rt::unwind::register::hf93dcfca71eaeedaBtI
3: 0x711836e0 - rt::unwind::begin_unwind_inner::h1c26c49e466c04e9LqI
4: 0x6f4e29 - diagnostic::SpanHandler::span_bug::h13d9b44f0a605030nnB
5: 0x6f5465 - diagnostic::Handler::bug::hb88abd22760a97693sB
6: 0x1081af1 - middle::ty::substd_enum_variants::h652b7145d0050673Vq7
7: 0x1081373 - middle::ty::substd_enum_variants::h652b7145d0050673Vq7
8: 0x10637b7 - middle::ty::TraitPredicate<'tcx>.RegionEscape::has_regions_escaping_depth::h4332861124e51a36iR9
9: 0x10386c8 - middle::traits::select::SelectionContext<'cx, 'tcx>::select::h5152e335d3335b0b3NQ
10: 0x1047018 - middle::traits::select::SelectionContext<'cx, 'tcx>::closure_typer::h2ad939045ad278ffONQ
11: 0x1045277 - middle::ty::Predicate<'tcx>...std..cmp..PartialEq::ne::hb9348ef9ca6483fdT92
12: 0x103f626 - middle::ty::Predicate<'tcx>...std..cmp..PartialEq::ne::hb9348ef9ca6483fdT92
13: 0x103d7b7 - middle::ty::ProjectionPredicate<'tcx>...std..clone..Clone::clone::ha5e6eda673804f45iv3
14: 0x10348cf - middle::traits::fulfill::FulfillmentContext<'tcx>::select_new_obligations::h18d2468924b2bc20xDO
15: 0x1033f2b - middle::traits::fulfill::FulfillmentContext<'tcx>::select_where_possible::h43612618c609155c6DO
16: 0x16947de - check::FnCtxt<'a, 'tcx>.ty..ClosureTyper<'tcx>::closure_upvars::h4d2d960d8f47db518Hn
17: 0x16caee6 - check::LvaluePreference...std..fmt..Debug::fmt::h8786612addfd7375tMp
18: 0x17401c1 - check::callee::CallResolution<'tcx>.Repr<'tcx>::repr::h04de2749584f8541lqm
19: 0x17950bf - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
20: 0x1791ea1 - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
21: 0x177688b - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
22: 0x17804d8 - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
23: 0x177bb14 - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
24: 0x168468b - check::FnCtxt<'a, 'tcx>.ty..ClosureTyper<'tcx>::closure_upvars::h4d2d960d8f47db518Hn
25: 0x1795635 - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
26: 0x1760a08 - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
27: 0x1734829 - check::callee::CallResolution<'tcx>.DeferredCallResolution<'tcx>::resolve::hcc66066c231187905rm
28: 0x1730f8f - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::hb45c2700a7bbe868pVo
29: 0x172f0dd - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::hb45c2700a7bbe868pVo
30: 0x175d18a - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
31: 0x1734829 - check::callee::CallResolution<'tcx>.DeferredCallResolution<'tcx>::resolve::hcc66066c231187905rm
32: 0x1730f8f - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::hb45c2700a7bbe868pVo
33: 0x172f0dd - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::hb45c2700a7bbe868pVo
34: 0x179b84b - check::UnresolvedTypeAction...std..clone..Clone::clone::h4af893540a13f8a1lQp
35: 0x174d1c1 - check::GatherLocalsVisitor<'a, 'tcx>.Visitor<'tcx>::visit_item::hceaf85db2079e370EZn
36: 0x172b502 - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::hb45c2700a7bbe868pVo
37: 0x174849f - check::CheckItemTypesVisitor<'a, 'tcx>.Visitor<'tcx>::visit_ty::h052b2547f6a9f346sMn
38: 0x17425a2 - check::CheckItemTypesVisitor<'a, 'tcx>.Visitor<'tcx>::visit_item::h3825f10c694ef4b96Ln
39: 0x1814d98 - check_crate::h0c1ffccf36595c1a1oC
40: 0x180f18c - check_crate::h0c1ffccf36595c1a1oC
41: 0x652df97b - driver::phase_3_run_analysis_passes::h4f4155770758209cgGa
42: 0x652c2c72 - driver::compile_input::h26f65b3844aecdf5Qba
43: 0x65376df3 - run_compiler::hbef16719e0bfa262S4b
44: 0x65374bff - run::hb658b94f918c924fy4b
45: 0x65373fda - run::hb658b94f918c924fy4b
46: 0x7125946c - rust_try
47: 0x71259449 - rust_try
48: 0x653742c1 - run::hb658b94f918c924fy4b
49: 0x712139d4 - sys::tcp::TcpListener::bind::h2dcec942e16be4c4OSG
50: 0x7ffa967b13d2 - BaseThreadInitThunk