Skip to content

Commit

Permalink
cxx-qt-gen: leave use statements in the CXX bridge
Browse files Browse the repository at this point in the history
Related to #404
  • Loading branch information
ahayzen-kdab committed Jul 21, 2023
1 parent 4d7effa commit e878d8f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 44 deletions.
25 changes: 1 addition & 24 deletions crates/cxx-qt-gen/src/generator/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl GeneratedRustBlocks {
Ok(GeneratedRustBlocks {
cxx_mod: parser.passthrough_module.clone(),
cxx_mod_contents: vec![generate_include(parser)?],
cxx_qt_mod_contents: parser.cxx_qt_data.uses.clone(),
cxx_qt_mod_contents: vec![],
namespace: parser.cxx_qt_data.namespace.clone(),
qobjects: parser
.cxx_qt_data
Expand Down Expand Up @@ -124,29 +124,6 @@ mod tests {
assert_eq!(rust.qobjects.len(), 1);
}

#[test]
fn test_generated_rust_blocks_uses() {
let module: ItemMod = parse_quote! {
#[cxx_qt::bridge(namespace = "cxx_qt")]
mod ffi {
use std::collections::HashMap;

extern "RustQt" {
#[cxx_qt::qobject]
type MyObject = super::MyObjectRust;
}
}
};
let parser = Parser::from(module).unwrap();

let rust = GeneratedRustBlocks::from(&parser).unwrap();
assert_eq!(rust.cxx_mod.content.unwrap().1.len(), 0);
assert_eq!(rust.cxx_mod_contents.len(), 1);
assert_eq!(rust.cxx_qt_mod_contents.len(), 1);
assert_eq!(rust.namespace, "cxx_qt");
assert_eq!(rust.qobjects.len(), 1);
}

#[test]
fn test_generated_rust_blocks_cxx_file_stem() {
let module: ItemMod = parse_quote! {
Expand Down
19 changes: 0 additions & 19 deletions crates/cxx-qt-gen/src/parser/cxxqtdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ pub struct ParsedCxxQtData {
pub qobjects: BTreeMap<Ident, ParsedQObject>,
/// The namespace of the CXX-Qt module
pub namespace: String,
/// Any `use` statements end up in the CXX-Qt generated module
pub uses: Vec<Item>,
}

impl ParsedCxxQtData {
Expand Down Expand Up @@ -202,11 +200,6 @@ impl ParsedCxxQtData {
pub fn parse_cxx_qt_item(&mut self, item: Item) -> Result<Option<Item>> {
match item {
Item::Impl(imp) => self.parse_impl(imp),
Item::Use(_) => {
// Any use statements go into the CXX-Qt generated block
self.uses.push(item);
Ok(None)
}
Item::ForeignMod(foreign_mod) => self.parse_foreign_mod(foreign_mod),
_ => Ok(Some(item)),
}
Expand Down Expand Up @@ -523,18 +516,6 @@ mod tests {
assert_eq!(cxx_qt_data.qobjects[&qobject_ident()].others.len(), 1);
}

#[test]
fn test_find_and_merge_cxx_qt_item_uses() {
let mut cxx_qt_data = create_parsed_cxx_qt_data();

let item: Item = parse_quote! {
use std::collections::HashMap;
};
let result = cxx_qt_data.parse_cxx_qt_item(item).unwrap();
assert!(result.is_none());
assert_eq!(cxx_qt_data.uses.len(), 1);
}

#[test]
fn test_find_and_merge_cxx_qt_item_passthrough() {
let mut cxx_qt_data = create_parsed_cxx_qt_data();
Expand Down
2 changes: 1 addition & 1 deletion crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub mod ffi {
x: A,
y: B,
}
use super::MyTrait;
unsafe extern "C++" {
include ! (< QtCore / QStringListModel >);
}
Expand Down Expand Up @@ -208,7 +209,6 @@ pub mod ffi {
fn cxx_qt_ffi_rust_mut(self: Pin<&mut SecondObject>) -> Pin<&mut SecondObjectRust>;
}
}
use super::MyTrait;
impl ffi::MyObject {
#[doc = "Getter for the Q_PROPERTY "]
#[doc = "property_name"]
Expand Down

0 comments on commit e878d8f

Please sign in to comment.