Skip to content

Commit be7c164

Browse files
committed
transpile: simplify import_type
1 parent 230a73d commit be7c164

File tree

1 file changed

+6
-12
lines changed
  • c2rust-transpile/src/translator

1 file changed

+6
-12
lines changed

c2rust-transpile/src/translator/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,19 +5369,13 @@ impl<'c> Translation<'c> {
53695369
}
53705370

53715371
fn import_type(&self, ctype: CTypeId) {
5372-
for Import {
5373-
decl_id,
5374-
ident_name,
5375-
} in self.imports_for_type(ctype)
5376-
{
5377-
self.add_import(decl_id, &ident_name)
5378-
}
5372+
self.add_imports(&self.imports_for_type(ctype))
53795373
}
53805374

5381-
fn imports_for_type(&self, ctype: CTypeId) -> Vec<Import> {
5375+
fn imports_for_type(&self, ctype: CTypeId) -> IndexSet<Import> {
53825376
use self::CTypeKind::*;
53835377

5384-
let mut imports = vec![];
5378+
let mut imports = IndexSet::default();
53855379

53865380
let type_kind = &self.ast_context[ctype].kind;
53875381
match type_kind {
@@ -5407,7 +5401,7 @@ impl<'c> Translation<'c> {
54075401
| Reference(CQualTypeId { ctype, .. })
54085402
| BlockPointer(CQualTypeId { ctype, .. })
54095403
| TypeOf(ctype)
5410-
| Complex(ctype) => imports = self.imports_for_type(*ctype),
5404+
| Complex(ctype) => imports.extend(self.imports_for_type(*ctype)),
54115405
Enum(decl_id) | Typedef(decl_id) | Union(decl_id) | Struct(decl_id) => {
54125406
let mut decl_id = *decl_id;
54135407
// if the `decl` has been "squashed", get the corresponding `decl_id`
@@ -5420,7 +5414,7 @@ impl<'c> Translation<'c> {
54205414
.borrow()
54215415
.resolve_decl_name(decl_id)
54225416
.expect("Expected decl name");
5423-
imports.push(Import {
5417+
imports.insert(Import {
54245418
decl_id,
54255419
ident_name,
54265420
});
@@ -5431,7 +5425,7 @@ impl<'c> Translation<'c> {
54315425

54325426
// Rust doesn't use void for return type, so skip
54335427
if *type_kind != Void {
5434-
imports = self.imports_for_type(*ctype);
5428+
imports.extend(self.imports_for_type(*ctype));
54355429
}
54365430

54375431
// Param Types

0 commit comments

Comments
 (0)