Skip to content

Commit 0acc26b

Browse files
Allow two signals with same idents but different self types and improve spans
* Add span to callables generation to improve error messages * Stops adding signals to typenames * Fix clippy lints Closes #1171
1 parent 2cf1b4a commit 0acc26b

File tree

9 files changed

+128
-107
lines changed

9 files changed

+128
-107
lines changed

crates/cxx-qt-gen/src/generator/rust/inherit.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ pub fn generate(
3131
})
3232
.collect::<Vec<TokenStream>>();
3333

34+
let span = method.method.span();
35+
3436
let ident = &method.method_fields.name.rust_unqualified();
3537
let cxx_name_string = &method.wrapper_ident().to_string();
3638
let self_param = if method.mutable {
37-
quote! { self: Pin<&mut #qobject_name> }
39+
quote_spanned! { span => self: Pin<&mut #qobject_name> }
3840
} else {
39-
quote! { self: &#qobject_name }
41+
quote_spanned! { span => self: &#qobject_name }
4042
};
4143
let return_type = &method.method.sig.output;
4244

4345
let mut unsafe_block = None;
46+
// Needs to be unspanned or clippy breaks surrounding the safety comment
4447
let mut unsafe_call = Some(quote! { unsafe });
4548
if method.safe {
4649
std::mem::swap(&mut unsafe_call, &mut unsafe_block);
@@ -50,7 +53,7 @@ pub fn generate(
5053
let namespace = qobject_names.namespace_tokens();
5154

5255
syn::parse2(quote_spanned! {
53-
method.method.span() =>
56+
span =>
5457
#unsafe_block extern "C++" {
5558
#[cxx_name = #cxx_name_string]
5659
#namespace

crates/cxx-qt-gen/src/generator/rust/property/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ mod tests {
310310
#[doc = "Connect the given function pointer to the signal "]
311311
#[doc = "trivialPropertyChanged"]
312312
#[doc = ", so that when the signal is emitted the function pointer is executed."]
313-
pub fn connect_trivial_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
313+
pub fn connect_trivial_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
314314
{
315315
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_trivial_property_changed(
316316
self,
@@ -330,7 +330,7 @@ mod tests {
330330
#[doc = ", so that when the signal is emitted the function pointer is executed."]
331331
#[doc = "\n"]
332332
#[doc = "Note that this method uses a AutoConnection connection type."]
333-
pub fn on_trivial_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
333+
pub fn on_trivial_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QMetaObjectConnectionGuard
334334
{
335335
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_trivial_property_changed(
336336
self,
@@ -435,7 +435,7 @@ mod tests {
435435
#[doc = "Connect the given function pointer to the signal "]
436436
#[doc = "opaquePropertyChanged"]
437437
#[doc = ", so that when the signal is emitted the function pointer is executed."]
438-
pub fn connect_opaque_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
438+
pub fn connect_opaque_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
439439
{
440440
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_opaque_property_changed(
441441
self,
@@ -455,7 +455,7 @@ mod tests {
455455
#[doc = ", so that when the signal is emitted the function pointer is executed."]
456456
#[doc = "\n"]
457457
#[doc = "Note that this method uses a AutoConnection connection type."]
458-
pub fn on_opaque_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
458+
pub fn on_opaque_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QMetaObjectConnectionGuard
459459
{
460460
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_opaque_property_changed(
461461
self,
@@ -560,7 +560,7 @@ mod tests {
560560
#[doc = "Connect the given function pointer to the signal "]
561561
#[doc = "unsafePropertyChanged"]
562562
#[doc = ", so that when the signal is emitted the function pointer is executed."]
563-
pub fn connect_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
563+
pub fn connect_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
564564
{
565565
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_unsafe_property_changed(
566566
self,
@@ -580,7 +580,7 @@ mod tests {
580580
#[doc = ", so that when the signal is emitted the function pointer is executed."]
581581
#[doc = "\n"]
582582
#[doc = "Note that this method uses a AutoConnection connection type."]
583-
pub fn on_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard
583+
pub fn on_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QMetaObjectConnectionGuard
584584
{
585585
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_unsafe_property_changed(
586586
self,

0 commit comments

Comments
 (0)