Skip to content

Commit 7fca33d

Browse files
Fix: Silence warning about unused base class
For some reason when using CXX-Qt as a dependency outside of this repository, the warning about the unused struct wasn't being silenced. This PR should fix that issue
1 parent 65b199f commit 7fca33d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,17 @@ fn generate_qobject_definitions(
127127

128128
let base_upcast = if let Some(base) = base {
129129
let base_name = type_names.lookup(&base)?.rust_qualified();
130-
vec![quote! { impl cxx_qt::Upcast<#base_name> for #cpp_struct_qualified {} }]
130+
vec![
131+
quote! { impl cxx_qt::Upcast<#base_name> for #cpp_struct_qualified {} },
132+
// Until we can actually implement the Upcast trait properly, we just need to silence
133+
// the warning that the base class is otherwise unused.
134+
// This can be done with an unnamed import and the right attributes
135+
quote! {
136+
#[allow(unused_imports)]
137+
#[allow(dead_code)]
138+
use #base_name as _;
139+
},
140+
]
131141
} else {
132142
vec![]
133143
};

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ mod inheritance {
7777
}
7878
}
7979
impl cxx_qt::Upcast<inheritance::QAbstractItemModel> for inheritance::MyObject {}
80+
#[allow(unused_imports)]
81+
#[allow(dead_code)]
82+
use inheritance::QAbstractItemModel as _;
8083
#[doc(hidden)]
8184
pub fn create_rs_my_object_rust() -> std::boxed::Box<MyObjectRust> {
8285
std::boxed::Box::new(core::default::Default::default())

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ pub mod ffi {
430430
}
431431
}
432432
impl cxx_qt::Upcast<ffi::QStringListModel> for ffi::MyObject {}
433+
#[allow(unused_imports)]
434+
#[allow(dead_code)]
435+
use ffi::QStringListModel as _;
433436
impl ffi::MyObject {
434437
#[doc = "Getter for the Q_PROPERTY "]
435438
#[doc = "property_name"]

0 commit comments

Comments
 (0)