Skip to content

Commit 7f221d6

Browse files
committed
transpile: prune_unwanted_decls only after setting prenamed_decls
1 parent 240a611 commit 7f221d6

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,14 @@ impl TypedAstContext {
11531153
}
11541154
}
11551155

1156+
// If a typedef names an anonymous decl, and that decl is wanted,
1157+
// then the typedef is also wanted.
1158+
for (&decl_id, &subdecl_id) in &self.prenamed_decls {
1159+
if wanted.contains(&subdecl_id) {
1160+
wanted.insert(decl_id);
1161+
}
1162+
}
1163+
11561164
// Unset c_main if we are not retaining its declaration
11571165
if let Some(main_id) = self.c_main {
11581166
if !wanted.contains(&main_id) {

c2rust-transpile/src/translator/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ pub fn translate(
708708
None
709709
};
710710

711+
// Identify typedefs that name unnamed types and collapse the two declarations
712+
// into a single name and declaration, eliminating the typedef altogether.
713+
t.ast_context.set_prenamed_decls();
714+
711715
// Headers often pull in declarations that are unused;
712716
// we simplify the translator output by omitting those.
713717
t.ast_context
@@ -737,10 +741,6 @@ pub fn translate(
737741
prefix_names(&mut t, prefix);
738742
}
739743

740-
// Identify typedefs that name unnamed types and collapse the two declarations
741-
// into a single name and declaration, eliminating the typedef altogether.
742-
t.ast_context.set_prenamed_decls();
743-
744744
for (&decl_id, &subdecl_id) in &t.ast_context.prenamed_decls {
745745
if let CDeclKind::Typedef { ref name, .. } = t.ast_context[decl_id].kind {
746746
t.type_converter

0 commit comments

Comments
 (0)