Skip to content

Commit 285215f

Browse files
committed
cxx-qt-gen: don't import Pin in hidden module resolving IDE integration
Now that impls are outside of the bridge the developer needs to import Pin anyway. Closes #417
1 parent 7fc3692 commit 285215f

File tree

16 files changed

+80
-82
lines changed

16 files changed

+80
-82
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4949
- Generation of getter and setter for private Rust fields
5050
- Generation of mutable getter for properties, instead use `rust_mut`
5151

52+
### Fixed
53+
54+
- Do not import `Pin` in hidden module as invokables are outside now, resolving IDE integration
55+
5256
## [0.5.3](https://github.com/KDAB/cxx-qt/compare/v0.5.2...v0.5.3) - 2023-05-19
5357

5458
### Fixed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mod tests {
138138
parse_quote! {
139139
impl MyObjectRust {
140140
#[doc(hidden)]
141-
pub fn set_trivial_property(&mut self, cpp: Pin<&mut MyObject>, value: i32) {
141+
pub fn set_trivial_property(&mut self, cpp: core::pin::Pin<&mut MyObject>, value: i32) {
142142
cpp.set_trivial_property(value);
143143
}
144144
}
@@ -150,7 +150,7 @@ mod tests {
150150
impl MyObject {
151151
#[doc = "Setter for the Q_PROPERTY "]
152152
#[doc = "trivial_property"]
153-
pub fn set_trivial_property(mut self: Pin<&mut Self>, value: i32) {
153+
pub fn set_trivial_property(mut self: core::pin::Pin<&mut Self>, value: i32) {
154154
if self.trivial_property == value {
155155
return;
156156
}
@@ -212,7 +212,7 @@ mod tests {
212212
parse_quote! {
213213
impl MyObjectRust {
214214
#[doc(hidden)]
215-
pub fn set_opaque_property(&mut self, cpp: Pin<&mut MyObject>, value: UniquePtr<QColor>) {
215+
pub fn set_opaque_property(&mut self, cpp: core::pin::Pin<&mut MyObject>, value: UniquePtr<QColor>) {
216216
cpp.set_opaque_property(value);
217217
}
218218
}
@@ -224,7 +224,7 @@ mod tests {
224224
impl MyObject {
225225
#[doc = "Setter for the Q_PROPERTY "]
226226
#[doc = "opaque_property"]
227-
pub fn set_opaque_property(mut self: Pin<&mut Self>, value: UniquePtr<QColor>) {
227+
pub fn set_opaque_property(mut self: core::pin::Pin<&mut Self>, value: UniquePtr<QColor>) {
228228
if self.opaque_property == value {
229229
return;
230230
}
@@ -286,7 +286,7 @@ mod tests {
286286
parse_quote! {
287287
impl MyObjectRust {
288288
#[doc(hidden)]
289-
pub fn set_unsafe_property(&mut self, cpp: Pin<&mut MyObject>, value: *mut T) {
289+
pub fn set_unsafe_property(&mut self, cpp: core::pin::Pin<&mut MyObject>, value: *mut T) {
290290
cpp.set_unsafe_property(value);
291291
}
292292
}
@@ -298,7 +298,7 @@ mod tests {
298298
impl MyObject {
299299
#[doc = "Setter for the Q_PROPERTY "]
300300
#[doc = "unsafe_property"]
301-
pub fn set_unsafe_property(mut self: Pin<&mut Self>, value: *mut T) {
301+
pub fn set_unsafe_property(mut self: core::pin::Pin<&mut Self>, value: *mut T) {
302302
if self.unsafe_property == value {
303303
return;
304304
}
@@ -344,7 +344,7 @@ mod tests {
344344
#[doc = "\n"]
345345
#[doc = "Note that this method uses a AutoConnection connection type."]
346346
#[must_use]
347-
pub fn on_trivial_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
347+
pub fn on_trivial_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
348348
{
349349
self.connect_trivial_property_changed(func, CxxQtConnectionType::AutoConnection)
350350
}
@@ -385,7 +385,7 @@ mod tests {
385385
#[doc = "\n"]
386386
#[doc = "Note that this method uses a AutoConnection connection type."]
387387
#[must_use]
388-
pub fn on_opaque_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
388+
pub fn on_opaque_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
389389
{
390390
self.connect_opaque_property_changed(func, CxxQtConnectionType::AutoConnection)
391391
}
@@ -426,7 +426,7 @@ mod tests {
426426
#[doc = "\n"]
427427
#[doc = "Note that this method uses a AutoConnection connection type."]
428428
#[must_use]
429-
pub fn on_unsafe_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
429+
pub fn on_unsafe_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
430430
{
431431
self.connect_unsafe_property_changed(func, CxxQtConnectionType::AutoConnection)
432432
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn generate(
4242
quote! {
4343
impl #rust_struct_name_rust {
4444
#[doc(hidden)]
45-
pub fn #setter_rust(&mut self, cpp: Pin<&mut #cpp_class_name_rust>, value: #ty) {
45+
pub fn #setter_rust(&mut self, cpp: core::pin::Pin<&mut #cpp_class_name_rust>, value: #ty) {
4646
cpp.#setter_rust(value);
4747
}
4848
}
@@ -51,7 +51,7 @@ pub fn generate(
5151
impl #cpp_class_name_rust {
5252
#[doc = "Setter for the Q_PROPERTY "]
5353
#[doc = #ident_str]
54-
pub fn #setter_rust(mut self: Pin<&mut Self>, value: #ty) {
54+
pub fn #setter_rust(mut self: core::pin::Pin<&mut Self>, value: #ty) {
5555
if self.#ident == value {
5656
// don't want to set the value again and reemit the signal,
5757
// as this can cause binding loops

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ pub fn generate_rust_signals(
4343
})
4444
.collect::<Vec<TokenStream>>();
4545

46-
let self_type = if signal.mutable {
47-
quote! { Pin<&mut #qobject_name> }
46+
let (self_type, self_type_cxx) = if signal.mutable {
47+
(
48+
quote! { core::pin::Pin<&mut #qobject_name> },
49+
quote! { Pin<&mut #qobject_name> },
50+
)
4851
} else {
49-
quote! { &#qobject_name }
52+
(quote! { &#qobject_name }, quote! { &#qobject_name })
5053
};
5154

5255
let mut unsafe_block = None;
@@ -63,7 +66,7 @@ pub fn generate_rust_signals(
6366
#unsafe_block extern "C++" {
6467
#(#attrs)*
6568
#[rust_name = #signal_name_rust_str]
66-
#unsafe_call fn #signal_name_cpp(self: #self_type, #(#parameters),*);
69+
#unsafe_call fn #signal_name_cpp(self: #self_type_cxx, #(#parameters),*);
6770
}
6871
},
6972
quote! {
@@ -73,7 +76,7 @@ pub fn generate_rust_signals(
7376
#[doc = ", so that when the signal is emitted the function pointer is executed."]
7477
#[must_use]
7578
#[rust_name = #connect_ident_rust_str]
76-
fn #connect_ident_cpp(self: #self_type, func: #unsafe_call fn(#self_type, #(#parameters),*), conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
79+
fn #connect_ident_cpp(self: #self_type_cxx, func: #unsafe_call fn(#self_type_cxx, #(#parameters),*), conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
7780
}
7881
},
7982
],
@@ -169,7 +172,7 @@ mod tests {
169172
#[doc = "\n"]
170173
#[doc = "Note that this method uses a AutoConnection connection type."]
171174
#[must_use]
172-
pub fn on_ready(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
175+
pub fn on_ready(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
173176
{
174177
self.connect_ready(func, CxxQtConnectionType::AutoConnection)
175178
}
@@ -244,7 +247,7 @@ mod tests {
244247
#[doc = "\n"]
245248
#[doc = "Note that this method uses a AutoConnection connection type."]
246249
#[must_use]
247-
pub fn on_data_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, trivial: i32, opaque: UniquePtr<QColor>)) -> CxxQtQMetaObjectConnection
250+
pub fn on_data_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, trivial: i32, opaque: UniquePtr<QColor>)) -> CxxQtQMetaObjectConnection
248251
{
249252
self.connect_data_changed(func, CxxQtConnectionType::AutoConnection)
250253
}
@@ -311,7 +314,7 @@ mod tests {
311314
#[doc = "\n"]
312315
#[doc = "Note that this method uses a AutoConnection connection type."]
313316
#[must_use]
314-
pub fn on_unsafe_signal(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, param: *mut T)) -> CxxQtQMetaObjectConnection
317+
pub fn on_unsafe_signal(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, param: *mut T)) -> CxxQtQMetaObjectConnection
315318
{
316319
self.connect_unsafe_signal(func, CxxQtConnectionType::AutoConnection)
317320
}
@@ -377,7 +380,7 @@ mod tests {
377380
#[doc = "\n"]
378381
#[doc = "Note that this method uses a AutoConnection connection type."]
379382
#[must_use]
380-
pub fn on_existing_signal(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
383+
pub fn on_existing_signal(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
381384
{
382385
self.connect_existing_signal(func, CxxQtConnectionType::AutoConnection)
383386
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn generate(
9393
#[doc(hidden)]
9494
fn queue<F>(cxx_qt_thread: &#cxx_qt_thread_ident, f: F) -> std::result::Result<(), cxx::Exception>
9595
where
96-
F: FnOnce(std::pin::Pin<&mut #cpp_struct_ident>),
96+
F: FnOnce(core::pin::Pin<&mut #cpp_struct_ident>),
9797
F: Send + 'static,
9898
{
9999
// Wrap the given closure and pass in to C++ function as an opaque type
@@ -102,7 +102,7 @@ pub fn generate(
102102
#[allow(clippy::boxed_local)]
103103
#[doc(hidden)]
104104
fn func(
105-
obj: std::pin::Pin<&mut #cpp_struct_ident>,
105+
obj: core::pin::Pin<&mut #cpp_struct_ident>,
106106
arg: std::boxed::Box<#cxx_qt_thread_queued_fn_ident>,
107107
) {
108108
(arg.inner)(obj)
@@ -129,7 +129,7 @@ pub fn generate(
129129
pub struct #cxx_qt_thread_queued_fn_ident {
130130
// An opaque Rust type is required to be Sized.
131131
// https://github.com/dtolnay/cxx/issues/665
132-
inner: std::boxed::Box<dyn FnOnce(std::pin::Pin<&mut #cpp_struct_ident>) + Send>,
132+
inner: std::boxed::Box<dyn FnOnce(core::pin::Pin<&mut #cpp_struct_ident>) + Send>,
133133
}
134134
},
135135
],
@@ -228,7 +228,7 @@ mod tests {
228228
#[doc(hidden)]
229229
fn queue<F>(cxx_qt_thread: &MyObjectCxxQtThread, f: F) -> std::result::Result<(), cxx::Exception>
230230
where
231-
F: FnOnce(std::pin::Pin<&mut MyObject>),
231+
F: FnOnce(core::pin::Pin<&mut MyObject>),
232232
F: Send + 'static,
233233
{
234234
// Wrap the given closure and pass in to C++ function as an opaque type
@@ -237,7 +237,7 @@ mod tests {
237237
#[allow(clippy::boxed_local)]
238238
#[doc(hidden)]
239239
fn func(
240-
obj: std::pin::Pin<&mut MyObject>,
240+
obj: core::pin::Pin<&mut MyObject>,
241241
arg: std::boxed::Box<MyObjectCxxQtThreadQueuedFn>,
242242
) {
243243
(arg.inner)(obj)
@@ -267,7 +267,7 @@ mod tests {
267267
pub struct MyObjectCxxQtThreadQueuedFn {
268268
// An opaque Rust type is required to be Sized.
269269
// https://github.com/dtolnay/cxx/issues/665
270-
inner: std::boxed::Box<dyn FnOnce(std::pin::Pin<&mut MyObject>) + Send>,
270+
inner: std::boxed::Box<dyn FnOnce(core::pin::Pin<&mut MyObject>) + Send>,
271271
}
272272
},
273273
);

crates/cxx-qt-gen/src/writer/rust/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn cxx_qt_common_blocks(qobject: &GeneratedRustQObject) -> Vec<TokenStream> {
5353
self.cxx_qt_ffi_rust()
5454
}
5555

56-
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
56+
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
5757
self.cxx_qt_ffi_rust_mut()
5858
}
5959
}
@@ -154,7 +154,6 @@ pub fn write_rust(generated: &GeneratedRustBlocks) -> TokenStream {
154154
/// Internal CXX-Qt module, made public temporarily between API changes
155155
pub mod #cxx_qt_mod_ident {
156156
use super::#cxx_mod_ident::*;
157-
use std::pin::Pin;
158157
use cxx_qt::CxxQtType;
159158

160159
#[doc(hidden)]
@@ -359,7 +358,6 @@ mod tests {
359358
#[doc = r" Internal CXX-Qt module, made public temporarily between API changes"]
360359
pub mod cxx_qt_ffi {
361360
use super::ffi::*;
362-
use std::pin::Pin;
363361
use cxx_qt::CxxQtType;
364362

365363
#[doc(hidden)]
@@ -389,7 +387,7 @@ mod tests {
389387
fn rust(&self) -> &Self::Rust {
390388
self.cxx_qt_ffi_rust()
391389
}
392-
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
390+
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
393391
self.cxx_qt_ffi_rust_mut()
394392
}
395393
}
@@ -468,7 +466,6 @@ mod tests {
468466
#[doc = r" Internal CXX-Qt module, made public temporarily between API changes"]
469467
pub mod cxx_qt_ffi {
470468
use super::ffi::*;
471-
use std::pin::Pin;
472469
use cxx_qt::CxxQtType;
473470

474471
#[doc(hidden)]
@@ -498,7 +495,7 @@ mod tests {
498495
fn rust(&self) -> &Self::Rust {
499496
self.cxx_qt_ffi_rust()
500497
}
501-
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
498+
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
502499
self.cxx_qt_ffi_rust_mut()
503500
}
504501
}
@@ -525,7 +522,7 @@ mod tests {
525522
fn rust(&self) -> &Self::Rust {
526523
self.cxx_qt_ffi_rust()
527524
}
528-
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
525+
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
529526
self.cxx_qt_ffi_rust_mut()
530527
}
531528
}

crates/cxx-qt-gen/test_outputs/inheritance.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ use self::cxx_qt_inheritance::*;
7575
pub mod cxx_qt_inheritance {
7676
use super::inheritance::*;
7777
use cxx_qt::CxxQtType;
78-
use std::pin::Pin;
7978
#[doc(hidden)]
8079
type UniquePtr<T> = cxx::UniquePtr<T>;
8180
type MyObjectRust = super::MyObjectRust;
@@ -95,7 +94,7 @@ pub mod cxx_qt_inheritance {
9594
fn rust(&self) -> &Self::Rust {
9695
self.cxx_qt_ffi_rust()
9796
}
98-
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
97+
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
9998
self.cxx_qt_ffi_rust_mut()
10099
}
101100
}

crates/cxx-qt-gen/test_outputs/invokables.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ use self::cxx_qt_ffi::*;
176176
pub mod cxx_qt_ffi {
177177
use super::ffi::*;
178178
use cxx_qt::CxxQtType;
179-
use std::pin::Pin;
180179
#[doc(hidden)]
181180
type UniquePtr<T> = cxx::UniquePtr<T>;
182181
type MyObjectRust = super::MyObjectRust;
@@ -192,13 +191,13 @@ pub mod cxx_qt_ffi {
192191
f: F,
193192
) -> std::result::Result<(), cxx::Exception>
194193
where
195-
F: FnOnce(std::pin::Pin<&mut MyObject>),
194+
F: FnOnce(core::pin::Pin<&mut MyObject>),
196195
F: Send + 'static,
197196
{
198197
#[allow(clippy::boxed_local)]
199198
#[doc(hidden)]
200199
fn func(
201-
obj: std::pin::Pin<&mut MyObject>,
200+
obj: core::pin::Pin<&mut MyObject>,
202201
arg: std::boxed::Box<MyObjectCxxQtThreadQueuedFn>,
203202
) {
204203
(arg.inner)(obj)
@@ -219,7 +218,7 @@ pub mod cxx_qt_ffi {
219218
}
220219
#[doc(hidden)]
221220
pub struct MyObjectCxxQtThreadQueuedFn {
222-
inner: std::boxed::Box<dyn FnOnce(std::pin::Pin<&mut MyObject>) + Send>,
221+
inner: std::boxed::Box<dyn FnOnce(core::pin::Pin<&mut MyObject>) + Send>,
223222
}
224223
impl cxx_qt::Locking for MyObject {}
225224
#[doc(hidden)]
@@ -276,7 +275,7 @@ pub mod cxx_qt_ffi {
276275
fn rust(&self) -> &Self::Rust {
277276
self.cxx_qt_ffi_rust()
278277
}
279-
fn rust_mut(self: core::pin::Pin<&mut Self>) -> Pin<&mut Self::Rust> {
278+
fn rust_mut(self: core::pin::Pin<&mut Self>) -> core::pin::Pin<&mut Self::Rust> {
280279
self.cxx_qt_ffi_rust_mut()
281280
}
282281
}

0 commit comments

Comments
 (0)