Skip to content

Commit 956c74f

Browse files
ahayzen-kdabBe-ing
authored andcommitted
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 a345666 commit 956c74f

File tree

16 files changed

+69
-74
lines changed

16 files changed

+69
-74
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4141
### Fixed
4242

4343
- Do not use -bundle otherwise CMake builds are missing qt-static-initalizers (note this is broken in rustc 1.69)
44+
- Do not import `Pin` in hidden module as invokables are outside now, resolving IDE integration
4445

4546
### Removed
4647

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ mod tests {
128128
impl MyObject {
129129
#[doc = "Setter for the Q_PROPERTY "]
130130
#[doc = "trivial_property"]
131-
pub fn set_trivial_property(mut self: Pin<&mut Self>, value: i32) {
131+
pub fn set_trivial_property(mut self: core::pin::Pin<&mut Self>, value: i32) {
132132
if self.trivial_property == value {
133133
return;
134134
}
@@ -180,7 +180,7 @@ mod tests {
180180
impl MyObject {
181181
#[doc = "Setter for the Q_PROPERTY "]
182182
#[doc = "opaque_property"]
183-
pub fn set_opaque_property(mut self: Pin<&mut Self>, value: UniquePtr<QColor>) {
183+
pub fn set_opaque_property(mut self: core::pin::Pin<&mut Self>, value: UniquePtr<QColor>) {
184184
if self.opaque_property == value {
185185
return;
186186
}
@@ -232,7 +232,7 @@ mod tests {
232232
impl MyObject {
233233
#[doc = "Setter for the Q_PROPERTY "]
234234
#[doc = "unsafe_property"]
235-
pub fn set_unsafe_property(mut self: Pin<&mut Self>, value: *mut T) {
235+
pub fn set_unsafe_property(mut self: core::pin::Pin<&mut Self>, value: *mut T) {
236236
if self.unsafe_property == value {
237237
return;
238238
}
@@ -278,7 +278,7 @@ mod tests {
278278
#[doc = "\n"]
279279
#[doc = "Note that this method uses a AutoConnection connection type."]
280280
#[must_use]
281-
pub fn on_trivial_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
281+
pub fn on_trivial_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
282282
{
283283
self.connect_trivial_property_changed(func, CxxQtConnectionType::AutoConnection)
284284
}
@@ -319,7 +319,7 @@ mod tests {
319319
#[doc = "\n"]
320320
#[doc = "Note that this method uses a AutoConnection connection type."]
321321
#[must_use]
322-
pub fn on_opaque_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
322+
pub fn on_opaque_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
323323
{
324324
self.connect_opaque_property_changed(func, CxxQtConnectionType::AutoConnection)
325325
}
@@ -360,7 +360,7 @@ mod tests {
360360
#[doc = "\n"]
361361
#[doc = "Note that this method uses a AutoConnection connection type."]
362362
#[must_use]
363-
pub fn on_unsafe_property_changed(self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
363+
pub fn on_unsafe_property_changed(self: core::pin::Pin<&mut MyObject>, func: fn(core::pin::Pin<&mut MyObject>, )) -> CxxQtQMetaObjectConnection
364364
{
365365
self.connect_unsafe_property_changed(func, CxxQtConnectionType::AutoConnection)
366366
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn generate(
4141
impl #cpp_class_name_rust {
4242
#[doc = "Setter for the Q_PROPERTY "]
4343
#[doc = #ident_str]
44-
pub fn #setter_rust(mut self: Pin<&mut Self>, value: #ty) {
44+
pub fn #setter_rust(mut self: core::pin::Pin<&mut Self>, value: #ty) {
4545
if self.#ident == value {
4646
// don't want to set the value again and reemit the signal,
4747
// 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)