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

rustc panicks when dealing with reference to functions in enum variants #27119

Closed
rohel01 opened this issue Jul 18, 2015 · 4 comments
Closed
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@rohel01
Copy link

rohel01 commented Jul 18, 2015

Summary of the bug is in the title

I tried with this code :

enum Event {
    ENTRY,
    EXIT,
}

struct Data;

struct State<'a> {
    f: Fn(&mut Data, &Event) -> &'a Signal<'a>,
}

enum Signal<'a> {
    UNHANDLED,
    HANDLED,
    TRAN(Fn(&mut Data, &Event) -> &'a Signal<'a>),
}

struct FSM<'a>  {
    current : Option<&'a State<'a>>,
    data : Data,
}

impl <'a> FSM<'a> {

    pub fn start(&mut self) {
        match self.current {
            None => panic!("Ola !"),
            Some(current) => {(current.f)(&mut self.data, &Event::ENTRY);},
            }

    }

    pub fn event(&mut self,event : Event) {
        let signal = (self.current.unwrap().f)(&mut self.data, &event);
    }

}

I expected rustc would have kept yelling at me about errors in my code :)
Instead, I get the following output

[miK@i5760-miK bug]$ cargo build --verbose
   Compiling hello_world v0.0.1 (file:///home/miK/workspaces/Rust/bug)
     Running `rustc src/lib.rs --crate-name hello_world --crate-type lib -g --out-dir /home/miK/workspaces/Rust/bug/target/debug --emit=dep-info,link -L dependency=/home/miK/workspaces/Rust/bug/target/debug -L dependency=/home/miK/workspaces/Rust/bug/target/debug/deps`
src/lib.rs:2:1: 5:2 warning: enum is never used: `Event`, #[warn(dead_code)] on by default
src/lib.rs:2 enum Event {
src/lib.rs:3     ENTRY,
src/lib.rs:4     EXIT,
src/lib.rs:5 }
src/lib.rs:7:1: 7:13 warning: struct is never used: `Data`, #[warn(dead_code)] on by default
src/lib.rs:7 struct Data;
             ^~~~~~~~~~~~
src/lib.rs:9:1: 11:2 warning: struct is never used: `State`, #[warn(dead_code)] on by default
src/lib.rs:9 struct State<'a> {
src/lib.rs:10     f: Fn(&mut Data, &Event) -> &'a Signal<'a>,
src/lib.rs:11 }
src/lib.rs:13:1: 17:2 warning: enum is never used: `Signal`, #[warn(dead_code)] on by default
src/lib.rs:13 enum Signal<'a> {
src/lib.rs:14     UNHANDLED,
src/lib.rs:15     HANDLED,
src/lib.rs:16     TRAN(Fn(&mut Data, &Event) -> &'a Signal<'a>),
src/lib.rs:17 }
src/lib.rs:19:1: 22:2 warning: struct is never used: `FSM`, #[warn(dead_code)] on by default
src/lib.rs:19 struct FSM<'a>  {
src/lib.rs:20     current : Option<&'a State<'a>>,
src/lib.rs:21     data : Data,
src/lib.rs:22 }
src/lib.rs:20:5: 20:36 warning: struct field is never used: `current`, #[warn(dead_code)] on by default
src/lib.rs:20     current : Option<&'a State<'a>>,
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:21:5: 21:16 warning: struct field is never used: `data`, #[warn(dead_code)] on by default
src/lib.rs:21     data : Data,
                  ^~~~~~~~~~~
src/lib.rs:26:5: 32:6 warning: method is never used: `start`, #[warn(dead_code)] on by default
src/lib.rs:26     pub fn start(&mut self) {
src/lib.rs:27         match self.current {
src/lib.rs:28             None => panic!("Ola !"),
src/lib.rs:29             Some(current) => {(current.f)(&mut self.data, &Event::ENTRY);},
src/lib.rs:30             }
src/lib.rs:31         
              ...
src/lib.rs:34:5: 36:6 warning: method is never used: `event`, #[warn(dead_code)] on by default
src/lib.rs:34     pub fn event(&mut self,event : Event) {
src/lib.rs:35         let signal = (self.current.unwrap().f)(&mut self.data, &event);
src/lib.rs:36     }
src/lib.rs:35:13: 35:19 warning: unused variable: `signal`, #[warn(unused_variables)] on by default
src/lib.rs:35         let signal = (self.current.unwrap().f)(&mut self.data, &event);
                          ^~~~~~
error: internal compiler error: unexpected panic
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 'Unexpected type returned from struct_tail: Signal for ty=Signal', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/librustc_trans/trans/type_of.rs:366

stack backtrace:
   1:     0x7f4a6dfdf529 - sys::backtrace::write::ha3b8868b13c6f5b594r
   2:     0x7f4a6dfe7449 - panicking::on_panic::h0d4f0a7bb69824a9iJw
   3:     0x7f4a6dfa8242 - rt::unwind::begin_unwind_inner::h6eae1ff9ccde81e1sow
   4:     0x7f4a6dfa8fd7 - rt::unwind::begin_unwind_fmt::h1b64aa0dc7f97d91ynw
   5:     0x7f4a6cd84041 - trans::type_of::in_memory_type_of::h8394fa8ab4d78a04xNL
   6:     0x7f4a6ce4c42f - trans::type_of::type_of_rust_fn::hd912a43908d09915gBL
   7:     0x7f4a6cd9092b - trans::declare::declare_rust_fn::h9be6db25c327fe6dRNz
   8:     0x7f4a6cea5442 - trans::meth::trans_object_shim::hb599a1c833cfc4e8BwJ
   9:     0x7f4a6cdee7a8 - trans::meth::trans_method_callee::hccc5b8b91d6ac958o2I
  10:     0x7f4a6ce6f845 - trans::callee::trans_call_inner::h3335664676729396018
  11:     0x7f4a6ce4fc13 - trans::expr::trans_rvalue_dps_unadjusted::h6f98c3ba8230a493FkB
  12:     0x7f4a6ce245dc - trans::expr::trans_into::h5caadbac159cf74aXaA
  13:     0x7f4a6ce2414a - trans::controlflow::trans_stmt_semi::h1d1c29c8dbdd3907D2u
  14:     0x7f4a6cda84ba - trans::controlflow::trans_block::he9bca081d3f8c1c7z3u
  15:     0x7f4a6ce4e45d - trans::expr::trans_rvalue_dps_unadjusted::h6f98c3ba8230a493FkB
  16:     0x7f4a6ce245dc - trans::expr::trans_into::h5caadbac159cf74aXaA
  17:     0x7f4a6ce8b007 - trans::_match::trans_match_inner::h57034bb4c897c3296uI
  18:     0x7f4a6ce4e425 - trans::expr::trans_rvalue_dps_unadjusted::h6f98c3ba8230a493FkB
  19:     0x7f4a6ce245dc - trans::expr::trans_into::h5caadbac159cf74aXaA
  20:     0x7f4a6cda8806 - trans::controlflow::trans_block::he9bca081d3f8c1c7z3u
  21:     0x7f4a6cda7121 - trans::base::trans_closure::h502004b16ea01ff9jHh
  22:     0x7f4a6cda8dfa - trans::base::trans_fn::h5f2be6a1df79e5691Rh
  23:     0x7f4a6cdac652 - trans::base::trans_item::hfa0f4f4b559a2855dgi
  24:     0x7f4a6cdb9a32 - trans::base::trans_crate::hf005d8f63d50ea8004i
  25:     0x7f4a6e537466 - driver::phase_4_translate_to_llvm::h86819ae7902c932bnOa
  26:     0x7f4a6e513266 - driver::compile_input::h6e596544d26b4394Qba
  27:     0x7f4a6e5c9041 - run_compiler::haa6c0289fab7415475b
  28:     0x7f4a6e5c6892 - boxed::F.FnBox<A>::call_box::h10721825727138786690
  29:     0x7f4a6e5c5e59 - rt::unwind::try::try_fn::h6014602198652783625
  30:     0x7f4a6e05fb58 - rust_try_inner
  31:     0x7f4a6e05fb45 - rust_try
  32:     0x7f4a6e5c60f4 - boxed::F.FnBox<A>::call_box::h5510246712457526188
  33:     0x7f4a6dfe61e1 - sys::thread::Thread::new::thread_start::h11fbc90f6ba541f9zvv
  34:     0x7f4a68877ee4 - start_thread
  35:     0x7f4a6dc29d1c - clone
  36:                0x0 - <unknown>

Could not compile `hello_world`.

Caused by:
  Process didn't exit successfully: `rustc src/lib.rs --crate-name hello_world --crate-type lib -g --out-dir /home/miK/workspaces/Rust/bug/target/debug --emit=dep-info,link -L dependency=/home/miK/workspaces/Rust/bug/target/debug -L dependency=/home/miK/workspaces/Rust/bug/target/debug/deps` (exit code: 101)

Metadata

[miK@i5760-miK bug]$ rustc --verbose --version
rustc 1.1.0 (35ceea399 2015-06-19)
binary: rustc
commit-hash: 35ceea3997c79a3b7562e89b462ab76af5b86b22
commit-date: 2015-06-19
host: x86_64-unknown-linux-gnu
release: 1.1.0
@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jul 19, 2015
@arielb1
Copy link
Contributor

arielb1 commented Jul 19, 2015

This is the enum struct_tail bug again.

@rohel01
Copy link
Author

rohel01 commented Jul 20, 2015

Should I upgrade rustc version ?

@arielb1
Copy link
Contributor

arielb1 commented Jul 20, 2015

@rohel01

This is a bug that should be fixed. It is still a bug in 1.3.0. The problem is that your enum Signal contains the unsized variants TRAN(Fn(&mut Data, &Event) -> &'a Signal<'a>). Unsized variants currently cause an ICE, but are probably not what you want (I imagine you instead want Box<Fn(&mut Data, &Event) -> &'a Signal<'a>>, and the same for State).

@apasel422
Copy link
Contributor

This is a duplicate of #16812.

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

No branches or pull requests

5 participants