Skip to content

ICE trying to port to new ops::Fn with trait-parametrized impl #23827

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

Closed
rsaarelm opened this issue Mar 29, 2015 · 2 comments · Fixed by #24367
Closed

ICE trying to port to new ops::Fn with trait-parametrized impl #23827

rsaarelm opened this issue Mar 29, 2015 · 2 comments · Fixed by #24367
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@rsaarelm
Copy link

Script to reproduce:

#!/bin/bash

cat > /tmp/fn_ice.rs << EOF
#![feature(core, unboxed_closures)]

pub struct Prototype {
    pub target: u32
}

trait Component {
    fn apply(self, e: u32);
}

impl<C: Component> Fn<(C,)> for Prototype {
    extern "rust-call" fn call(&self, (comp,): (C,)) -> Prototype {
        comp.apply(self.target);
        *self
    }
}

impl<C: Component> FnMut<(C,)> for Prototype {
    extern "rust-call" fn call_mut(&mut self, (comp,): (C,)) -> Prototype {
        Fn::call(*&self, (comp,))
    }
}

impl<C: Component> FnOnce<(C,)> for Prototype {
    extern "rust-call" fn call_once(self, (comp,): (C,)) -> Prototype {
        Fn::call(&self, (comp,))
    }
}

fn main() {}
EOF

RUST_BACKTRACE=1 rustc /tmp/fn_ice.rs
rustc --version

Output:

/tmp/fn_ice.rs:20:9: 20:34 error: internal compiler error: cat_expr Errd
/tmp/fn_ice.rs:20         Fn::call(*&self, (comp,))
                          ^~~~~~~~~~~~~~~~~~~~~~~~~
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>', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:130

stack backtrace:
   1:     0x7fded6be1af9 - sys::backtrace::write::h8fb4e343117fc1c5HyD
   2:     0x7fded6c09718 - panicking::on_panic::h93647013dcbd3994ZOJ
   3:     0x7fded6b3d803 - rt::unwind::begin_unwind_inner::hd1fc6b2d31010710GuJ
   4:     0x7fded3ff706d - rt::unwind::begin_unwind::h8658016321657282922
   5:     0x7fded3ff7013 - diagnostic::SpanHandler::span_bug::had6443bf384adbf3JaB
   6:     0x7fded4879fa3 - session::Session::span_bug::h6a7a032f0a598052BRn
   7:     0x7fded58b3ecf - check::regionck::visit_expr::hdfd865c1888e71cf1Hd
   8:     0x7fded58af2fe - check::regionck::Rcx<'a, 'tcx>::visit_fn_body::haec01bb8e2116544ekd
   9:     0x7fded593c006 - check::check_bare_fn::h661e8d61a11643593nn
  10:     0x7fded5941136 - check::check_method_body::h58ab2862cf5cc872TVn
  11:     0x7fded5938972 - check::check_item::h399c12ee5fd19c10OGn
  12:     0x7fded5a08dd6 - check_crate::closure.35999
  13:     0x7fded5a03c4a - check_crate::h609b704cb69c3426OmC
  14:     0x7fded723dcc8 - driver::phase_3_run_analysis_passes::h93ff07476d50900drGa
  15:     0x7fded7223e3f - driver::compile_input::hbb8012e70cc155f0Rba
  16:     0x7fded72d42e2 - run_compiler::h31d988b263419921s2b
  17:     0x7fded72d20e3 - thunk::F.Invoke<A, R>::invoke::h12881802307748552982
  18:     0x7fded72d1579 - rt::unwind::try::try_fn::h10611962194889117110
  19:     0x7fded6c835b8 - rust_try_inner
  20:     0x7fded6c835a5 - rust_try
  21:     0x7fded72d189c - thunk::F.Invoke<A, R>::invoke::h15479254083495500308
  22:     0x7fded6bf6248 - sys::thread::create::thread_start::h21751a1d907ece81soI
  23:     0x7fded0ae2373 - start_thread
  24:     0x7fded67b327c - __clone
  25:                0x0 - <unknown>

rustc 1.0.0-nightly (199bdcfef 2015-03-26) (built 2015-03-27)

Meta

rustc 1.0.0-nightly (199bdcf 2015-03-26) (built 2015-03-27)
binary: rustc
commit-hash: 199bdcf
commit-date: 2015-03-26
build-date: 2015-03-27
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly

@ebfull
Copy link
Contributor

ebfull commented Mar 29, 2015

Providing the associated type for FnOnce avoids this ICE.

impl<C: Component> FnOnce<(C,)> for Prototype {
    type Output = Prototype;

    extern "rust-call" fn call_once(self, (comp,): (C,)) -> Prototype {
        Fn::call(&self, (comp,))
    }
}

@rsaarelm
Copy link
Author

This works. Thanks!

@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 29, 2015
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.

3 participants