-
Notifications
You must be signed in to change notification settings - Fork 94
Fix: Constructors no longer fail silently #1295
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
base: main
Are you sure you want to change the base?
Fix: Constructors no longer fail silently #1295
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1295 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 75 75
Lines 13038 13064 +26
=========================================
+ Hits 13038 13064 +26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a9f26a3 to
080cb5f
Compare
18a487e to
6547d3d
Compare
683889c to
c016271
Compare
- A shim trait is used to check whether the user declared a constructor - This is implemented by the bridge if you add the constructor trait in bridge - This will then allow you to implemented constructor for your type - This prevents constructors not being used silently
- Add lifetime - Update span
c016271 to
101ca81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well, but needs some better user-facing documentation.
Please also update the Changelog to mention this new feature :)
| fn threading_drop(cxx_qt_thread: core::pin::Pin<&mut CxxQtThread<Self>>); | ||
| } | ||
|
|
||
| #[doc(hidden)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried the PR, it works well, but the discoverability of what caused the error still needs improving!
If I e.g. remove the constructor declaration from qml_features/properties.rs, what I get is:
Long error message
error[E0277]: the trait bound `RustProperties: ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not satisfied
--> examples/qml_features/rust/src/properties.rs:139:5
|
139 | / fn route_arguments(
140 | | arguments: (bool, &'a QUrl, &'a QUrl, &'a QString),
141 | | ) -> (
142 | | Self::NewArguments,
143 | | Self::BaseArguments,
144 | | Self::InitializeArguments,
145 | | ) {
| |_____^ the trait `ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not implemented for `RustProperties`
|
= help: the trait `ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not implemented for `RustProperties`
but trait `ConstructorDeclared<()>` is implemented for it
= help: for that trait implementation, expected `()`, found `(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)`
note: required by a bound in `Constructor`
--> /home/kdab/Documents/projects/3371-Rust-RnD/cxx-qt/crates/cxx-qt/src/lib.rs:313:47
|
313 | pub trait Constructor<Arguments>: CxxQtType + ConstructorDeclared<Arguments> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Constructor`
error[E0277]: the trait bound `RustProperties: ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not satisfied
--> examples/qml_features/rust/src/properties.rs:150:5
|
150 | / fn new(
151 | | (connected, connected_url, previous_connected_url, status_message): Self::NewArguments,
152 | | ) -> Self::Rust {
| |___________________^ the trait `ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not implemented for `RustProperties`
|
= help: the trait `ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not implemented for `RustProperties`
but trait `ConstructorDeclared<()>` is implemented for it
= help: for that trait implementation, expected `()`, found `(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)`
note: required by a bound in `Constructor`
--> /home/kdab/Documents/projects/3371-Rust-RnD/cxx-qt/crates/cxx-qt/src/lib.rs:313:47
|
313 | pub trait Constructor<Arguments>: CxxQtType + ConstructorDeclared<Arguments> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Constructor`
error[E0277]: the trait bound `RustProperties: ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not satisfied
--> examples/qml_features/rust/src/properties.rs:134:75
|
134 | impl<'a> cxx_qt::Constructor<(bool, &'a QUrl, &'a QUrl, &'a QString)> for qobject::RustProperties {
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not implemented for `RustProperties`
|
= help: the trait `ConstructorDeclared<(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)>` is not implemented for `RustProperties`
but trait `ConstructorDeclared<()>` is implemented for it
= help: for that trait implementation, expected `()`, found `(bool, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QUrl, &'a cxx_qt_lib::QString)`
note: required by a bound in `Constructor`
--> /home/kdab/Documents/projects/3371-Rust-RnD/cxx-qt/crates/cxx-qt/src/lib.rs:313:47
|
313 | pub trait Constructor<Arguments>: CxxQtType + ConstructorDeclared<Arguments> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Constructor`
So now I know I did something wrong, but what?
The compiler helpfully points me me to the Constructor trait. But if I look at the docs for the constructor trait, I cannot click on ConstructorDeclared, and I cannot find the trait mentioned anywhere in the docs.
So either we:
- Make this not
#[doc(hidden)]and add documentation that says that you should not implement the trait yourself, but that adding the declaration to the bridge generates an implementation. - Describe this in the doc comment of the
Constructortrait.
impl Constructor<()> for ... {}in the bridge silently fails #1233