Skip to content

Conversation

@BenFordTytherington
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Jun 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f88253b) to head (bc1bc82).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BenFordTytherington BenFordTytherington force-pushed the missing-constructor-error branch 3 times, most recently from a9f26a3 to 080cb5f Compare June 18, 2025 09:53
@BenFordTytherington BenFordTytherington force-pushed the missing-constructor-error branch 2 times, most recently from 18a487e to 6547d3d Compare October 3, 2025 13:07
@BenFordTytherington BenFordTytherington force-pushed the missing-constructor-error branch 3 times, most recently from 683889c to c016271 Compare October 3, 2025 14:08
@BenFordTytherington BenFordTytherington marked this pull request as ready for review October 3, 2025 14:12
BenFordTytherington and others added 2 commits October 7, 2025 16:58
- 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
@BenFordTytherington BenFordTytherington force-pushed the missing-constructor-error branch from c016271 to 101ca81 Compare October 7, 2025 15:58
Copy link
Collaborator

@LeonMatthesKDAB LeonMatthesKDAB left a 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)]
Copy link
Collaborator

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 Constructor trait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing impl Constructor<()> for ... {} in the bridge silently fails

3 participants