-
Notifications
You must be signed in to change notification settings - Fork 102
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
Open
BenFordTytherington
wants to merge
3
commits into
KDAB:main
Choose a base branch
from
BenFordTytherington:missing-constructor-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,11 +208,24 @@ pub fn generate( | |
| let rust_struct_name_rust = qobject_names.rust_struct.rust_unqualified(); | ||
|
|
||
| for (index, constructor) in constructors.iter().enumerate() { | ||
| let mut arguments = TokenStream::new(); | ||
| for elem in &constructor.arguments { | ||
| arguments.extend(quote!(#elem,)); | ||
| } | ||
|
|
||
| let lifetime = constructor.lifetime.as_ref().map(|lifetime| { | ||
| quote! { | ||
| < #lifetime > | ||
| } | ||
| }); | ||
|
|
||
| result | ||
| .cxx_qt_mod_contents | ||
| .append(&mut vec![parse_quote_spanned! { | ||
| constructor.imp.span() => | ||
| impl #lifetime ::cxx_qt::ConstructorDeclared<(#arguments) > for #qobject_name_rust_qualified {} | ||
| }]); | ||
|
|
||
| let arguments_lifetime = | ||
| lifetime_of_arguments(&constructor.lifetime, &constructor.arguments)?; | ||
| let base_lifetime = | ||
|
|
@@ -599,8 +612,16 @@ mod tests { | |
| }, | ||
| ); | ||
|
|
||
| // Shim impl only appears once | ||
| assert_tokens_eq( | ||
| &blocks.cxx_qt_mod_contents[0], | ||
| quote! { | ||
| impl ::cxx_qt::ConstructorDeclared<()> for qobject::MyObject {} | ||
| }, | ||
| ); | ||
|
|
||
| assert_tokens_eq( | ||
| &blocks.cxx_qt_mod_contents[1], | ||
| quote! { | ||
| #[doc(hidden)] | ||
| pub fn route_arguments_MyObject_0() -> qobject::CxxQtConstructorArgumentsMyObject0 | ||
|
|
@@ -619,7 +640,7 @@ mod tests { | |
| }, | ||
| ); | ||
| assert_tokens_eq( | ||
| &blocks.cxx_qt_mod_contents[1], | ||
| &blocks.cxx_qt_mod_contents[2], | ||
| quote! { | ||
| #[doc(hidden)] | ||
| #[allow(unused_variables)] | ||
|
|
@@ -633,7 +654,7 @@ mod tests { | |
| }, | ||
| ); | ||
| assert_tokens_eq( | ||
| &blocks.cxx_qt_mod_contents[2], | ||
| &blocks.cxx_qt_mod_contents[3], | ||
| quote! { | ||
| #[doc(hidden)] | ||
| #[allow(unused_variables)] | ||
|
|
@@ -725,7 +746,14 @@ mod tests { | |
| ); | ||
|
|
||
| assert_tokens_eq( | ||
| &blocks.cxx_qt_mod_contents[3], | ||
| &blocks.cxx_qt_mod_contents[4], | ||
| quote! { | ||
| impl<'lifetime> ::cxx_qt::ConstructorDeclared<(*const QObject,)> for qobject::MyObject {} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so then all of these would have |
||
| }, | ||
| ); | ||
|
|
||
| assert_tokens_eq( | ||
| &blocks.cxx_qt_mod_contents[5], | ||
| quote! { | ||
| #[doc(hidden)] | ||
| pub fn route_arguments_MyObject_1<'lifetime>(arg0: *const QObject) -> qobject::CxxQtConstructorArgumentsMyObject1<'lifetime> | ||
|
|
@@ -753,7 +781,7 @@ mod tests { | |
| }, | ||
| ); | ||
| assert_tokens_eq( | ||
| &blocks.cxx_qt_mod_contents[4], | ||
| &blocks.cxx_qt_mod_contents[6], | ||
| quote! { | ||
| #[doc(hidden)] | ||
| #[allow(unused_variables)] | ||
|
|
@@ -767,7 +795,7 @@ mod tests { | |
| }, | ||
| ); | ||
| assert_tokens_eq( | ||
| &blocks.cxx_qt_mod_contents[5], | ||
| &blocks.cxx_qt_mod_contents[7], | ||
| quote! { | ||
| #[doc(hidden)] | ||
| #[allow(unused_variables)] | ||
|
|
@@ -806,7 +834,7 @@ mod tests { | |
| ]); | ||
|
|
||
| assert_eq!(blocks.cxx_mod_contents.len(), 10); | ||
| assert_eq!(blocks.cxx_qt_mod_contents.len(), 6); | ||
| assert_eq!(blocks.cxx_qt_mod_contents.len(), 8); | ||
|
|
||
| let namespace_attr = quote! { | ||
| #[namespace = "qobject::cxx_qt_MyObject"] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
CI complains i think about this lifetime fun, probably just add
#[allow(clippy::needless_lifetimes)]here for the generated code like we do elsewhere