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

compiler unexpectedly panicked #23729

Closed
dls opened this issue Mar 26, 2015 · 1 comment · Fixed by #24367
Closed

compiler unexpectedly panicked #23729

dls opened this issue Mar 26, 2015 · 1 comment · Fixed by #24367
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@dls
Copy link

dls commented Mar 26, 2015

I tried this code:

fn main() {
    let fib = {
        struct Recurrence {
            mem: [u64; 2],
            pos: usize,
        }

        impl Iterator for Recurrence {
            #[inline]
            fn next(&mut self) -> Option<u64> {
                if self.pos < 2 {
                    let next_val = self.mem[self.pos];
                    self.pos += 1;
                    Some(next_val)
                } else {
                    let next_val = (self.mem[0] + self.mem[1]);
                    self.mem[0] = self.mem[1];
                    self.mem[1] = next_val;
                    Some(next_val)
                }
            }
        }

        Recurrence { mem: [0, 1], pos: 0 }
    };

    for e in fib.take(10) {
        println!("{}", e)
    }
}

I expected to see this happen:

0
1
1
2
3
5
8
13
21
34

Instead, this happened:

$ RUST_BACKTRACE=1 cargo run
   Compiling hello_world v0.0.1 (file:///Users/dls/ac4/hello_world)
src/main.rs:27:5: 30:2 error: internal compiler error: cat_expr Errd
src/main.rs:27     for e in fib.take(10) {
src/main.rs:28         println!("{}", e)
src/main.rs:29     }
src/main.rs:30 }
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/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:130

Meta

rustc 1.0.0-nightly (123a754 2015-03-24) (built 2015-03-25)
binary: rustc
commit-hash: 123a754
commit-date: 2015-03-24
build-date: 2015-03-25
host: x86_64-apple-darwin
release: 1.0.0-nightly

Backtrace:

stack backtrace:
   1:        0x108671ea4 - sys::backtrace::write::h78053bbfb550960cgjD
   2:        0x10869d358 - panicking::on_panic::hc4e82bbd2a46726dR8I
   3:        0x1085ba76e - rt::unwind::begin_unwind_inner::h5e8e19c0097ac0cdBRI
   4:        0x107dcbcbe - rt::unwind::begin_unwind::h8176364159252686369
   5:        0x107dcbc6b - diagnostic::SpanHandler::span_bug::hdcd6dc2adc048426AaB
   6:        0x1055bdcec - session::Session::span_bug::hd2e8d90e6e32fe5bTHn
   7:        0x104d624db - check::regionck::visit_expr::h67ec4d109373a14f2Dd
   8:        0x104d69e7a - visit::walk_expr::h4641389526047920594
   9:        0x104d61353 - check::regionck::visit_expr::h67ec4d109373a14f2Dd
  10:        0x104d610c1 - check::regionck::visit_expr::h67ec4d109373a14f2Dd
  11:        0x104d69ecb - visit::walk_expr::h4641389526047920594
  12:        0x104d61353 - check::regionck::visit_expr::h67ec4d109373a14f2Dd
  13:        0x104d62e41 - check::regionck::visit_local::hd93c3707d09d90fd7Ad
  14:        0x104d69f5c - visit::walk_expr::h4641389526047920594
  15:        0x104d61783 - check::regionck::visit_expr::h67ec4d109373a14f2Dd
  16:        0x104d5d3c5 - check::regionck::Rcx<'a, 'tcx>::visit_fn_body::h91b65695e5e98981fgd
  17:        0x104dee2da - check::check_bare_fn::h4d8e30b5b0012b734jn
  18:        0x104de6184 - check::check_item::h4b4a2b730b65c17cMCn
  19:        0x104ebd782 - check_crate::closure.35881
  20:        0x104eb83da - check_crate::h4e5a2f60ebec7dccblC
  21:        0x104bf9417 - driver::phase_3_run_analysis_passes::h00707ed732905e83rGa
  22:        0x104bdf816 - driver::compile_input::h22976530edbb8120Rba
  23:        0x104c99313 - run_compiler::h6f6a07f7c4e7d147s2b
  24:        0x104c96ea5 - thunk::F.Invoke<A, R>::invoke::h5399241532089372082
  25:        0x104c96267 - rt::unwind::try::try_fn::h14095088624371570858
  26:        0x108723468 - rust_try_inner
  27:        0x108723455 - rust_try
  28:        0x104c96605 - thunk::F.Invoke<A, R>::invoke::h14770910994046267349
  29:        0x10868825d - sys::thread::create::thread_start::h3a4e0027cd5d22bdqPH
  30:     0x7fff902a9267 - _pthread_body
  31:     0x7fff902a91e4 - _pthread_start
@pnkfelix pnkfelix added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 26, 2015
@dls
Copy link
Author

dls commented Mar 26, 2015

if you add:

            type Item = u64;

To the iterator declaration the compiler no longer panics.

        impl Iterator for Recurrence {
            type Item = u64;

            #[inline]
            fn next(&mut self) -> Option<u64> {
                if self.pos < 2 {
                    let next_val = self.mem[self.pos];
                    self.pos += 1;
                    Some(next_val)
                } else {
                    let next_val = (self.mem[0] + self.mem[1]);
                    self.mem[0] = self.mem[1];
                    self.mem[1] = next_val;
                    Some(next_val)
                }
            }
        }

ebfull added a commit to ebfull/rust that referenced this issue Apr 13, 2015
An actual typeck error is the cause of many failed compilations but an
unrelated bug is being reported instead. It is triggered because a typeck
error is presumably not yet identified during compiler execution, which
would normally bypass an invariant in the presence of other errors. In
this particular situation, we delay the reporting of the bug until
abort_if_errors().

Closes rust-lang#23827, closes rust-lang#24356, closes rust-lang#23041, closes rust-lang#22897, closes rust-lang#23966,
closes rust-lang#24013, and closes rust-lang#23729
bors added a commit that referenced this issue Apr 26, 2015
An actual typeck error is the cause of many failed compilations but an
unrelated bug is being reported instead. It is triggered because a typeck
error is presumably not yet identified during compiler execution, which
would normally bypass an invariant in the presence of other errors. In
this particular situation, we delay the reporting of the bug until
abort_if_errors().

Closes #23827, closes #24356, closes #23041, closes #22897, closes #23966,
closes #24013, and closes #23729

**There is at least one situation where this bug may still be genuinely
triggered (#23437).**
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.

2 participants