Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BenFordTytherington
Copy link
Collaborator

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 (96d3233) to head (080cb5f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1295   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           75        75           
  Lines        12772     12787   +15     
=========================================
+ Hits         12772     12787   +15     

☔ 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 2 times, most recently from 76f5358 to a9f26a3 Compare June 18, 2025 09:36
- 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
@@ -216,6 +216,9 @@ pub trait Threading: Sized {
fn threading_drop(cxx_qt_thread: &mut CxxQtThread<Self>);
}

#[doc(hidden)]
pub trait ConstructorDeclared {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trait will need the same generics and type arguments as the constructor trait, so that we can make sure you actually declare the correct constructors inside the bridge.

Otherwise you could do stuff like:

#[cxx_qt::bridge]
mod qobject {
    // implements ConstructorDeclared
    impl cxx_qt::Constructor<(i32,)> for MyObject {}
}

impl cxx_qt::Constructor<(i32,)> for MyObject {
   // ...
}

// Additional constructor declared
// No compiler error!
impl cxx_qt::Constructor<()> for MyObject {
  // ...
}

and the trait bound would not catch it.

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
2 participants