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

signals: use #[must_use] when returning a QMetaObjectConnectionGuard #932

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 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 Down Expand Up @@ -413,7 +412,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 Down Expand Up @@ -539,7 +537,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 Down
7 changes: 0 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 Down Expand Up @@ -304,7 +303,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 Down Expand Up @@ -471,7 +469,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 Down Expand Up @@ -632,7 +629,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 Down Expand Up @@ -789,7 +785,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 Down Expand Up @@ -941,7 +936,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 Down Expand Up @@ -1085,7 +1079,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 Down
7 changes: 0 additions & 7 deletions crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ pub mod ffi {
>;
#[doc(hidden)]
#[namespace = "cxx_qt::multi_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_property_name_changed"]
fn MyObject_propertyNameChangedConnect(
self_value: Pin<&mut MyObject>,
Expand Down Expand Up @@ -140,7 +139,6 @@ pub mod ffi {
cxx_qt::signalhandler::CxxQtSignalHandler<super::MyObjectCxxQtSignalClosureready>;
#[doc(hidden)]
#[namespace = "cxx_qt::multi_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_ready"]
fn MyObject_readyConnect(
self_value: Pin<&mut MyObject>,
Expand Down Expand Up @@ -208,7 +206,6 @@ pub mod ffi {
>;
#[doc(hidden)]
#[namespace = "second_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "SecondObject_connect_property_name_changed"]
fn SecondObject_propertyNameChangedConnect(
self_value: Pin<&mut SecondObject>,
Expand Down Expand Up @@ -245,7 +242,6 @@ pub mod ffi {
cxx_qt::signalhandler::CxxQtSignalHandler<super::SecondObjectCxxQtSignalClosureready>;
#[doc(hidden)]
#[namespace = "second_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "SecondObject_connect_ready"]
fn SecondObject_readyConnect(
self_value: Pin<&mut SecondObject>,
Expand Down Expand Up @@ -295,7 +291,6 @@ pub mod ffi {
cxx_qt::signalhandler::CxxQtSignalHandler<super::QPushButtonCxxQtSignalClosureclicked>;
#[doc(hidden)]
#[namespace = "rust::cxxqtgen1"]
#[must_use]
#[rust_name = "QPushButton_connect_clicked"]
fn QPushButton_clickedConnect(
self_value: Pin<&mut QPushButton>,
Expand Down Expand Up @@ -326,7 +321,6 @@ pub mod ffi {
>;
#[doc(hidden)]
#[namespace = "mynamespace::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "ExternObject_connect_data_ready"]
fn ExternObject_dataReadyConnect(
self_value: Pin<&mut ExternObject>,
Expand Down Expand Up @@ -359,7 +353,6 @@ pub mod ffi {
>;
#[doc(hidden)]
#[namespace = "mynamespace::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "ExternObject_connect_error_occurred"]
fn ExternObject_errorOccurredConnect(
self_value: Pin<&mut ExternObject>,
Expand Down
2 changes: 0 additions & 2 deletions crates/cxx-qt-gen/test_outputs/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ mod ffi {
>;
#[doc(hidden)]
#[namespace = "cxx_qt::my_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_primitive_changed"]
fn MyObject_primitiveChangedConnect(
self_value: Pin<&mut MyObject>,
Expand Down Expand Up @@ -95,7 +94,6 @@ mod ffi {
>;
#[doc(hidden)]
#[namespace = "cxx_qt::my_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_trivial_changed"]
fn MyObject_trivialChangedConnect(
self_value: Pin<&mut MyObject>,
Expand Down
4 changes: 0 additions & 4 deletions crates/cxx-qt-gen/test_outputs/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ mod ffi {
cxx_qt::signalhandler::CxxQtSignalHandler<super::MyObjectCxxQtSignalClosureready>;
#[doc(hidden)]
#[namespace = "cxx_qt::my_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_ready"]
fn MyObject_readyConnect(
self_value: Pin<&mut MyObject>,
Expand Down Expand Up @@ -85,7 +84,6 @@ mod ffi {
cxx_qt::signalhandler::CxxQtSignalHandler<super::MyObjectCxxQtSignalClosuredataChanged>;
#[doc(hidden)]
#[namespace = "cxx_qt::my_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_data_changed"]
fn MyObject_dataChangedConnect(
self_value: Pin<&mut MyObject>,
Expand Down Expand Up @@ -124,7 +122,6 @@ mod ffi {
cxx_qt::signalhandler::CxxQtSignalHandler<super::MyObjectCxxQtSignalClosurenewData>;
#[doc(hidden)]
#[namespace = "cxx_qt::my_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "MyObject_connect_base_class_new_data"]
fn MyObject_newDataConnect(
self_value: Pin<&mut MyObject>,
Expand Down Expand Up @@ -173,7 +170,6 @@ mod ffi {
cxx_qt::signalhandler::CxxQtSignalHandler<super::QTimerCxxQtSignalClosuretimeout>;
#[doc(hidden)]
#[namespace = "cxx_qt::my_object::rust::cxxqtgen1"]
#[must_use]
#[rust_name = "QTimer_connect_timeout"]
fn QTimer_timeoutConnect(
self_value: Pin<&mut QTimer>,
Expand Down
3 changes: 2 additions & 1 deletion crates/cxx-qt/src/connectionguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use crate::QMetaObjectConnection;
///
/// Note that when this struct is dropped the connection is disconnected.
/// So to keep a connection active either hold onto the struct for the duration
/// that the connection should be active or call `release`.
/// that the connection should be active or call `release`, hence the `#[must_use]`.
#[must_use]
pub struct QMetaObjectConnectionGuard {
connection: QMetaObjectConnection,
}
Expand Down
9 changes: 6 additions & 3 deletions examples/cargo_without_cmake/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ fn main() {

if let Some(engine) = engine.as_mut() {
// Listen to a signal from the QML Engine
engine.as_qqmlengine().on_quit(|_| {
println!("QML Quit!");
});
engine
.as_qqmlengine()
.on_quit(|_| {
println!("QML Quit!");
})
.release();
}

// Start the app
Expand Down
Loading