Skip to content

Commit 018a315

Browse files
committed
transpile: only compute source ranges if emitting C decl map
1 parent 0c859e3 commit 018a315

File tree

1 file changed

+7
-5
lines changed
  • c2rust-transpile/src/translator

1 file changed

+7
-5
lines changed

c2rust-transpile/src/translator/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,11 @@ pub fn translate(
479479

480480
// Compute source ranges of top decls before pruning any, because pruned
481481
// decls may help inform the ranges of kept ones.
482-
let decl_source_ranges = t.ast_context.top_decl_locs();
482+
let decl_source_ranges = if tcfg.emit_c_decl_map {
483+
Some(t.ast_context.top_decl_locs())
484+
} else {
485+
None
486+
};
483487

484488
// Headers often pull in declarations that are unused;
485489
// we simplify the translator output by omitting those.
@@ -731,7 +735,7 @@ pub fn translate(
731735
.collect::<HashMap<_, _>>();
732736

733737
// Generate a map from Rust items to the source code of their C declarations.
734-
let decl_map = if tcfg.emit_c_decl_map {
738+
let decl_map = decl_source_ranges.and_then(|decl_source_ranges| {
735739
let mut path_to_c_source_range: HashMap<&Ident, (SrcLoc, SrcLoc)> = Default::default();
736740
for (decl, source_range) in decl_source_ranges {
737741
match converted_decls.get(&decl) {
@@ -811,9 +815,7 @@ pub fn translate(
811815
})
812816
.collect();
813817
Some(item_path_to_c_source)
814-
} else {
815-
None
816-
};
818+
});
817819

818820
t.ast_context.sort_top_decls_for_emitting();
819821

0 commit comments

Comments
 (0)