Skip to content

Commit 3918150

Browse files
fw-immunantkkysen
authored andcommitted
transpile: import struct/union names when creating their literals
1 parent 719fb2b commit 3918150

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

c2rust-transpile/src/translator/literals.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ impl<'c> Translation<'c> {
334334
.borrow()
335335
.resolve_decl_name(union_id)
336336
.unwrap();
337+
if let Some(cur_file) = self.cur_file.get() {
338+
log::debug!("in file {cur_file} importing union {union_name}, id {union_id:?}");
339+
self.add_import(cur_file, union_id, &union_name);
340+
}
337341
match self.ast_context.index(union_field_id).kind {
338342
CDeclKind::Field { typ: field_ty, .. } => {
339343
let val = if ids.is_empty() {

c2rust-transpile/src/translator/structs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ impl<'a> Translation<'a> {
398398
field_expr_ids: &[CExprId],
399399
) -> TranslationResult<WithStmts<Box<Expr>>> {
400400
let name = self.resolve_decl_inner_name(struct_id);
401+
if let Some(cur_file) = self.cur_file.get() {
402+
log::debug!("in file {cur_file} importing struct {name}, id {struct_id:?}");
403+
self.add_import(cur_file, struct_id, &name);
404+
}
401405

402406
let (field_decl_ids, platform_byte_size) = match self.ast_context.index(struct_id).kind {
403407
CDeclKind::Struct {

0 commit comments

Comments
 (0)