Skip to content

Commit 6f837e0

Browse files
committed
transpile: add tcfg: &TranspilerConfig to fn TypeConverter::new to simplify creation
There doesn't seem to be a point in calling `TypeConvert::new()` and then setting fields, vs. just setting them in `fn new` to begin with. We already don't want to `impl Default`.
1 parent cd9e6a8 commit 6f837e0

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

c2rust-transpile/src/convert_type.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::c_ast::*;
33
use crate::diagnostics::TranslationResult;
44
use crate::renamer::*;
55
use crate::translator::variadic::mk_va_list_ty;
6+
use crate::TranspilerConfig;
67
use crate::{CrateSet, ExternCrate};
78
use c2rust_ast_builder::{mk, properties::*};
89
use failure::format_err;
@@ -133,16 +134,9 @@ pub const RESERVED_NAMES: [&str; 100] = [
133134
];
134135

135136
impl TypeConverter {
136-
// We don't provide a `Default` impl to simplify future compatibility:
137-
// if `TypeConverter` ever gets fields incompatible with `Default`, then
138-
// cleaning out the uses of `impl Default for TypeConverter` can be a pain.
139-
// More practically, there is a single use of `TypeConverter::new` and no
140-
// current plans to use a `Default` impl, so providing it isn't worth the
141-
// potential breakage.
142-
#[allow(clippy::new_without_default)]
143-
pub fn new() -> TypeConverter {
137+
pub fn new(tcfg: &TranspilerConfig) -> TypeConverter {
144138
TypeConverter {
145-
translate_valist: false,
139+
translate_valist: tcfg.translate_valist,
146140
renamer: Renamer::new(&RESERVED_NAMES),
147141
fields: HashMap::new(),
148142
suffix_names: HashMap::new(),

c2rust-transpile/src/translator/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,9 +1533,7 @@ impl<'c> Translation<'c> {
15331533
main_file: &Path,
15341534
) -> Self {
15351535
let comment_context = CommentContext::new(&mut ast_context);
1536-
let mut type_converter = TypeConverter::new();
1537-
1538-
type_converter.translate_valist = tcfg.translate_valist;
1536+
let type_converter = TypeConverter::new(tcfg);
15391537

15401538
let main_file = ast_context
15411539
.find_file_id(main_file)

0 commit comments

Comments
 (0)