Skip to content

Commit e685e76

Browse files
committed
transpile: simplify logic for fn convert_decl errors since decl is already calculated
1 parent 81b8780 commit e685e76

File tree

1 file changed

+10
-17
lines changed
  • c2rust-transpile/src/translator

1 file changed

+10
-17
lines changed

c2rust-transpile/src/translator/mod.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,7 @@ pub fn translate(
698698
_ => false,
699699
};
700700
if needs_export {
701-
let decl_opt = t.ast_context.get_decl(top_id);
702-
let decl = decl_opt.unwrap();
701+
let decl = t.ast_context.get_decl(top_id).unwrap();
703702
let decl_file_id = t.ast_context.file_id(decl);
704703

705704
if t.tcfg.reorganize_definitions
@@ -709,21 +708,15 @@ pub fn translate(
709708
}
710709
match t.convert_decl(ctx, *top_id) {
711710
Err(e) => {
712-
let decl = &t.ast_context.get_decl(top_id);
713-
let msg = match decl {
714-
Some(decl) => {
715-
let decl_identifier = decl.kind.get_name().map_or_else(
716-
|| {
717-
t.ast_context
718-
.display_loc(&decl.loc)
719-
.map_or("Unknown".to_string(), |l| format!("at {}", l))
720-
},
721-
|name| name.clone(),
722-
);
723-
format!("Failed to translate {}: {}", decl_identifier, e)
724-
}
725-
_ => format!("Failed to translate declaration: {}", e,),
726-
};
711+
let decl_identifier = decl.kind.get_name().map_or_else(
712+
|| {
713+
t.ast_context
714+
.display_loc(&decl.loc)
715+
.map_or("Unknown".to_string(), |l| format!("at {}", l))
716+
},
717+
|name| name.clone(),
718+
);
719+
let msg = format!("Failed to translate {}: {}", decl_identifier, e);
727720
translate_failure(t.tcfg, &msg);
728721
}
729722
Ok(converted_decl) => {

0 commit comments

Comments
 (0)