gtk-rs / gtk4-rs

Rust bindings of GTK 4
https://gtk-rs.org/gtk4-rs/
MIT License
1.9k stars 174 forks source link

[BUG] Closure return no value but the caller expected a value of type #929

Closed kavan-mevada closed 2 years ago

kavan-mevada commented 2 years ago

Bug description

main.rs

use gtk::prelude::*;

fn main() {
    let application = gtk::Application::new(
        Some("com.github.gtk-rs.examples.composite_template"),
        Default::default(),
    );

    application.connect_activate(|app| {
        let win = ExApplicationWindow::new(app);
        win.show();
    });
    application.run();
}

use gtk::{gio, glib};

glib::wrapper! {
    pub struct ExApplicationWindow(ObjectSubclass<imp::ExApplicationWindow>)
        @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, @implements gio::ActionMap, gio::ActionGroup;
}

impl ExApplicationWindow {
    pub fn new<P: glib::IsA<gtk::Application>>(app: &P) -> Self {
        glib::Object::new(&[("application", app)]).expect("Failed to create ExApplicationWindow")
    }
}

mod imp {
    use gtk::prelude::*;
    use gtk::subclass::prelude::*;
    use gtk::{glib, CompositeTemplate};

    /// The private struct, which can hold widgets and other data.
    #[derive(Debug, Default, CompositeTemplate)]
    #[template(file = "window.ui")]
    pub struct ExApplicationWindow {}

    #[glib::object_subclass]
    impl ObjectSubclass for ExApplicationWindow {
        const NAME: &'static str = "ExApplicationWindow";
        type Type = super::ExApplicationWindow;
        type ParentType = gtk::ApplicationWindow;

        fn class_init(klass: &mut Self::Class) {
            Self::bind_template(klass);
            Self::bind_template_callbacks(klass);
        }

        fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
            obj.init_template();
        }
    }

    #[gtk::template_callbacks]
    impl ExApplicationWindow {
        #[template_callback(function = false)]
        fn search_started(&self, _entry: &gtk::SearchEntry) {}

        #[template_callback(function = false)]
        fn search_stopped(&self) {}

        #[template_callback(function = false)]
        fn search_entry_changed(&self, _entry: &gtk::SearchEntry) {}
    }

    impl ObjectImpl for ExApplicationWindow {
        fn constructed(&self, obj: &Self::Type) {
            self.parent_constructed(obj);
        }
    }

    impl WidgetImpl for ExApplicationWindow {}
    impl WindowImpl for ExApplicationWindow {}
    impl ApplicationWindowImpl for ExApplicationWindow {}
}

window.ui

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <template class="ExApplicationWindow" parent="GtkApplicationWindow">
    <property name="default-width">600</property>
    <property name="default-height">300</property>
    <property name="title">Example Application Window</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="headerbar">
        <property name="show-title-buttons">True</property>
        <child type="end">
          <object class="GtkSearchEntry" id="entry_a">
            <property name="width-request">300</property>
            <signal name="search-changed" handler="search_entry_changed" swapped="true"/>
            <signal name="search-started" handler="search_started" swapped="true"/>
            <signal name="stop-search" handler="search_stopped" swapped="true"/>
          </object>
        </child>
      </object>
    </child>
  </template>
</interface>

Cargo.toml

[dependencies]
adw = { version = "0.1.0", package = "libadwaita" }
gtk = { version = "0.4.6", package = "gtk4" }
gdk = { version = "0.4.6", package = "gdk4" }
glib = { version = "0.15.4" }
gio = { version = "0.15.4" }
once_cell = "1.9.0"

Way to reproduce situation:

  1. Click on SearchEntry
  2. Write something
  3. Press Escape key

Backtrace

thread 'main' panicked at 'Closure return no value but the caller expected a value of type ', /var/home/kavan/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-0.15.5/src/closure.rs:248:25

kavan-mevada commented 2 years ago
GtkSearchEntry
thread 'main' panicked at 'Closure return no value but the caller expected a value of type <invalid>', /var/home/kavan/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-0.15.5/src/closure.rs:248:25
stack backtrace:
   0:     0x55a6fc4cfabc - std::backtrace_rs::backtrace::libunwind::trace::h1f3307dc5706259d
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55a6fc4cfabc - std::backtrace_rs::backtrace::trace_unsynchronized::h13daa497d1661243
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55a6fc4cfabc - std::sys_common::backtrace::_print_fmt::h0bf9bf630cefe950
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x55a6fc4cfabc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6b74b64a6e4ec12e
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x55a6fc4ece9c - core::fmt::write::h17cd681f57a88542
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/core/src/fmt/mod.rs:1190:17
   5:     0x55a6fc4ccad8 - std::io::Write::write_fmt::h79e2c4cbb8773666
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/io/mod.rs:1657:15
   6:     0x55a6fc4d1727 - std::sys_common::backtrace::_print::h2700f5379cfe6b47
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x55a6fc4d1727 - std::sys_common::backtrace::print::h897f624ef35b988a
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x55a6fc4d1727 - std::panicking::default_hook::{{closure}}::ha87874d89e22ff34
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:295:22
   9:     0x55a6fc4d13ef - std::panicking::default_hook::h2bad94d1b644ac6e
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:314:9
  10:     0x55a6fc4d1e8a - std::panicking::rust_panic_with_hook::hfd8c91de33c5176e
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:698:17
  11:     0x55a6fc4d1b77 - std::panicking::begin_panic_handler::{{closure}}::h46119636dbe6db5e
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:588:13
  12:     0x55a6fc4cff64 - std::sys_common::backtrace::__rust_end_short_backtrace::h261f21d8a26becbf
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x55a6fc4d1879 - rust_begin_unwind
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:584:5
  14:     0x55a6fc46a3a3 - core::panicking::panic_fmt::h98621a2cee43fd9e
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/core/src/panicking.rs:143:14
  15:     0x55a6fc4898a7 - glib::closure::Closure::new_unsafe::marshal::h5c3ab0a79416759b
                               at /var/home/kavan/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-0.15.5/src/closure.rs:248:25
  16:     0x7f4666a8dd30 - g_closure_invoke
  17:     0x7f4666ab7e36 - <unknown>
  18:     0x7f466650ef82 - <unknown>
  19:     0x7f466651203b - <unknown>
  20:     0x7f46665b8362 - <unknown>
  21:     0x7f46665b8689 - <unknown>
  22:     0x7f4666747bbe - <unknown>
  23:     0x7f46664ac87f - <unknown>
  24:     0x7f46665c680c - <unknown>
  25:     0x7f4666688c10 - <unknown>
  26:     0x7f46666b814b - <unknown>
  27:     0x7f4666aab1e9 - g_signal_emit_valist
  28:     0x7f4666aab323 - g_signal_emit
  29:     0x7f4666747c73 - <unknown>
  30:     0x7f46666ca1de - <unknown>
  31:     0x7f4665e641bf - g_main_context_dispatch
  32:     0x7f4665eb92d8 - <unknown>
  33:     0x7f4665e61b40 - g_main_context_iteration
  34:     0x7f466602ab6d - g_application_run
  35:     0x55a6fc46d6e7 - <O as gio::application::ApplicationExtManual>::run_with_args::hee315b112d148455
                               at /var/home/kavan/.cargo/registry/src/github.com-1ecc6299db9ec823/gio-0.15.5/src/application.rs:30:13
  36:     0x55a6fc46d556 - <O as gio::application::ApplicationExtManual>::run::h35500bc7e63e6159
                               at /var/home/kavan/.cargo/registry/src/github.com-1ecc6299db9ec823/gio-0.15.5/src/application.rs:23:9
  37:     0x55a6fc471622 - searchentry::main::h9142798364d75e2a
                               at /var/home/kavan/Documents/searchentry/src/main.rs:13:5
  38:     0x55a6fc46c15b - core::ops::function::FnOnce::call_once::h167896f270eacb68
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/core/src/ops/function.rs:227:5
  39:     0x55a6fc46ff0e - std::sys_common::backtrace::__rust_begin_short_backtrace::h9bcbe818095c07b0
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/sys_common/backtrace.rs:122:18
  40:     0x55a6fc46bca1 - std::rt::lang_start::{{closure}}::he9e11e50f3135406
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/rt.rs:145:18
  41:     0x55a6fc4cf1a1 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h09c416c88f75ec81
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/core/src/ops/function.rs:259:13
  42:     0x55a6fc4cf1a1 - std::panicking::try::do_call::he64f7bc77fdeaf94
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:492:40
  43:     0x55a6fc4cf1a1 - std::panicking::try::hfe4b453f73051e2b
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:456:19
  44:     0x55a6fc4cf1a1 - std::panic::catch_unwind::hf57ef6941bd73066
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panic.rs:137:14
  45:     0x55a6fc4cf1a1 - std::rt::lang_start_internal::{{closure}}::h51e09db07b4e65ae
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/rt.rs:128:48
  46:     0x55a6fc4cf1a1 - std::panicking::try::do_call::h302e35bda53165bf
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:492:40
  47:     0x55a6fc4cf1a1 - std::panicking::try::h5521fc5513031976
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panicking.rs:456:19
  48:     0x55a6fc4cf1a1 - std::panic::catch_unwind::h9f4ed632723bab7c
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/panic.rs:137:14
  49:     0x55a6fc4cf1a1 - std::rt::lang_start_internal::h85453cf1e9d763f0
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/rt.rs:128:20
  50:     0x55a6fc46bc70 - std::rt::lang_start::hb045329651d43d2b
                               at /rustc/e789f3a3a3d96ebf99b7bbd95011527e5be32a11/library/std/src/rt.rs:144:17
  51:     0x55a6fc47184c - main
  52:     0x7f4665c1a590 - __libc_start_call_main
  53:     0x7f4665c1a649 - __libc_start_main_alias_1
  54:     0x55a6fc46ab25 - _start
  55:                0x0 - <unknown>
[Finished in 10.8s with exit code 101]