Fix: Constructors no longer fail silently#1295
Fix: Constructors no longer fail silently#1295BenFordTytherington wants to merge 3 commits intoKDAB:mainfrom
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 13108 13134 +26
=========================================
+ Hits 13108 13134 +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
c016271 to
101ca81
Compare
LeonMatthesKDAB
left a comment
There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
Updated some of the docs in Constructor to explain this.
b65156c to
31a4312
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
31a4312 to
ce2cd61
Compare
impl Constructor<()> for ... {}in the bridge silently fails #1233