Skip to content

Commit

Permalink
signals: use #[must_use] when returning a QMetaObjectConnectionGuard
Browse files Browse the repository at this point in the history
Before we used to return a QMetaObjectConnection which used to
disconnection now we have two types, so ensure #[must_use] is
in the right place.
  • Loading branch information
ahayzen-kdab committed Apr 18, 2024
1 parent 8b809e8 commit d442859
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
9 changes: 6 additions & 3 deletions crates/cxx-qt-gen/src/generator/rust/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_trivial_property_changed"]
fn MyObject_trivialPropertyChangedConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandlertrivialPropertyChanged, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -314,6 +313,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "trivialPropertyChanged"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_trivial_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_trivial_property_changed(
Expand All @@ -334,6 +334,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_trivial_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_trivial_property_changed(
Expand Down Expand Up @@ -413,7 +414,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_opaque_property_changed"]
fn MyObject_opaquePropertyChangedConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandleropaquePropertyChanged, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -440,6 +440,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "opaquePropertyChanged"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_opaque_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_opaque_property_changed(
Expand All @@ -460,6 +461,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_opaque_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_opaque_property_changed(
Expand Down Expand Up @@ -539,7 +541,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_unsafe_property_changed"]
fn MyObject_unsafePropertyChangedConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandlerunsafePropertyChanged, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -566,6 +567,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "unsafePropertyChanged"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_unsafe_property_changed(
Expand All @@ -586,6 +588,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_unsafe_property_changed(
Expand Down
21 changes: 14 additions & 7 deletions crates/cxx-qt-gen/src/generator/rust/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub fn generate_rust_signal(

#[doc(hidden)]
#[namespace = #namespace_str]
#[must_use]
#[rust_name = #free_connect_ident_rust_str]
fn #free_connect_ident_cpp(self_value: #self_type_cxx, signal_handler: #signal_handler_alias, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -136,6 +135,7 @@ pub fn generate_rust_signal(
#[doc = "Connect the given function pointer to the signal "]
#[doc = #signal_name_cpp_str]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn #connect_ident_rust<F: FnMut(#self_type_qualified, #(#parameters_qualified_type),*) + 'static>(self: #self_type_qualified, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(#module_ident::#free_connect_ident_rust(
Expand All @@ -153,6 +153,7 @@ pub fn generate_rust_signal(
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn #on_ident_rust<F: FnMut(#self_type_qualified, #(#parameters_qualified_type),*) + 'static>(self: #self_type_qualified, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(#module_ident::#free_connect_ident_rust(
Expand Down Expand Up @@ -304,7 +305,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_ready"]
fn MyObject_readyConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandlerready, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -331,6 +331,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "ready"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_ready<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready(
Expand All @@ -351,6 +352,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_ready<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready(
Expand Down Expand Up @@ -471,7 +473,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_data_changed"]
fn MyObject_dataChangedConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandlerdataChanged, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -498,6 +499,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "dataChanged"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_data_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, i32, cxx::UniquePtr<QColor>) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_data_changed(
Expand All @@ -518,6 +520,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_data_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, i32, cxx::UniquePtr<QColor>) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_data_changed(
Expand Down Expand Up @@ -632,7 +635,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_unsafe_signal"]
fn MyObject_unsafeSignalConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandlerunsafeSignal, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -659,6 +661,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "unsafeSignal"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_unsafe_signal<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, *mut T) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_unsafe_signal(
Expand All @@ -679,6 +682,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_unsafe_signal<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, *mut T) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_unsafe_signal(
Expand Down Expand Up @@ -789,7 +793,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_existing_signal"]
fn MyObject_baseNameConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandlerbaseName, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -816,6 +819,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "baseName"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_existing_signal<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_existing_signal(
Expand All @@ -836,6 +840,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_existing_signal<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_existing_signal(
Expand Down Expand Up @@ -941,7 +946,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_ready"]
fn MyObject_readyConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandlerready, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -968,6 +972,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "ready"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_ready<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready(
Expand All @@ -988,6 +993,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_ready<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready(
Expand Down Expand Up @@ -1085,7 +1091,6 @@ mod tests {

#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_ready"]
fn MyObject_readyConnect(self_value: Pin<&mut MyObject>, signal_handler: MyObjectCxxQtSignalHandlerready, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
}
Expand All @@ -1112,6 +1117,7 @@ mod tests {
#[doc = "Connect the given function pointer to the signal "]
#[doc = "ready"]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
pub fn connect_ready<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready(
Expand All @@ -1132,6 +1138,7 @@ mod tests {
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[doc = "\n"]
#[doc = "Note that this method uses a AutoConnection connection type."]
#[must_use]
pub fn on_ready<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
{
cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready(
Expand Down
Loading

0 comments on commit d442859

Please sign in to comment.