gtk-rs-core: `clone!`: Change default for weak ref upgrade failure from return to panic

At the moment if clone! fails to upgrade a weak reference it logs a message and returns ().

    button_decrease.connect_clicked(clone!(@weak button_increase =>
        move |_| {
            number.set(number.get() - 1);
            button_increase.set_label(&number.get().to_string());
    }));

When this occurs this is probably a bug. Changing the default to panic would make this more obvious.

Disadvantages:

  • Breaking change from old behavior that is not easy to detect
  • For gtk apps it is questionable if you want the app of a user to crash because of this

@sdroege, @YaLTeR

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (19 by maintainers)

Most upvoted comments

One thing to note from my experiments: ordering among attribute macros is fine, but using this means you can no longer use these captures from within macro_rules because those run after the attribute macros. The clone! macro still needs to be used in that case.

I will look into this, I don’t anticipate there will be many problems with macro order. The only thing we may have to avoid is using inside other internal proc macros.